Hi,
I try to create new branch from master, say it is feature/testagain. This is the response body from Bitbucket webhook:
{
"id": 949,
"repo_id": 1606,
"trigger": "@hook",
"number": 110,
"status": "pending",
"event": "push",
"action": "",
"link": "https://bitbucket.org/a-slug/repo-name/commits/a3daa180f74500dbd665c745348f4b9943a6e25f",
"timestamp": 0,
"message": "another try\n",
"before": "",
"after": "a3daa180f74500dbd665c745348f4b9943a6e25f",
"ref": "refs/heads/feature/testagain",
"source_repo": "",
"source": "feature/testagain",
"target": "feature/testagain",
"author_login": "",
"author_name": "A Name",
"author_email": "email@domain.com",
"author_avatar": "https://secure.gravatar.com/avatar/42fde7df94d52d48ae999f0eba239c45?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBP-5.png",
"sender": "",
"started": 0,
"finished": 0,
"created": 1574548289,
"updated": 1574548289,
"version": 1
}
But this is the context variable echoed from a step:
+ echo ""context"(build = "build"(action = "", after = "a3daa180f74500dbd665c745348f4b9943a6e25f", author_avatar = "https://secure.gravatar.com/avatar/42fde7df94d52d48ae999f0eba239c45?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBP-5.png", author_email = "email@domain.com", author_login = "", author_name = "A Name", before = "48dcb0876e4a704cb75e8ae5a6a53c5edfc8f42d", branch = "master", commit = "a3daa180f74500dbd665c745348f4b9943a6e25f", cron = "", environent = "", event = "push", link = "https://bitbucket.org/a-slug/repo-name/commits/a3daa180f74500dbd665c745348f4b9943a6e25f", message = "another try\n", params = {}, ref = "refs/heads/master", sender = "", source = "master", source_repo = "", target = "master", title = ""), repo = "repo"(active = True, branch = "master", config = ".drone.star", git_http_url = "https://bitbucket.org/a-slug/repo-name.git", git_ssh_url = "git@bitbucket.org:a-slug/repo-name.git", ignore_forks = False, ignore_pull_requests = False, link = "https://bitbucket.org/a-slug/repo-name", name = "repo-name", namespace = "a-slug", private = True, protected = False, slug = "a-slug/repo-name", trusted = False, uid = "{24139f0f-ff22-4b0c-bda3-3e7b3f48098a}", visibility = "private"))"
context(build = build(action = , after = a3daa180f74500dbd665c745348f4b9943a6e25f, author_avatar = https://secure.gravatar.com/avatar/42fde7df94d52d48ae999f0eba239c45?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBP-5.png, author_email = email@domain.com, author_login = , author_name = A Name, before = 48dcb0876e4a704cb75e8ae5a6a53c5edfc8f42d, branch = master, commit = a3daa180f74500dbd665c745348f4b9943a6e25f, cron = , environent = , event = push, link = https://bitbucket.org/a-slug/repo-name/commits/a3daa180f74500dbd665c745348f4b9943a6e25f, message = another try
/usr/drone/bin/init: line 26: , params = {}, ref = refs/heads/master, sender = , source = master, source_repo = , target = master, title = ), repo = repo(active = True, branch = master, config = .drone.star, git_http_url = https://bitbucket.org/a-slug/repo-name.git, git_ssh_url = git@bitbucket.org:a-slug/repo-name.git, ignore_forks = False, ignore_pull_requests = False, link = https://bitbucket.org/a-slug/repo-name, name = repo-name, namespace = a-slug, private = True, protected = False, slug = a-slug/repo-name, trusted = False, uid = {24139f0f-ff22-4b0c-bda3-3e7b3f48098a}, visibility = private)): not found
Why ref parameter from context is refs/heads/master?
This behaviour create a failed build each time I want to create new branch from master.
This is my .drone.star
:
def main(ctx):
print(ctx)
secrets_val = [
{"name": "A_SECRET", "path": "secret/data/foo", "key": "bar"},
]
steps=[]
steps.extend([
init(ctx),
])
drone=[]
drone.extend(secrets(secrets_val))
drone.extend([pipeline(ctx, steps)])
return drone
def pipeline(ctx, steps):
pipeline={
"kind": "pipeline",
"name": "%s" % ctx.repo.name,
"trigger": {
"ref": [
"refs/heads/master",
"refs/heads/develop",
"refs/heads/feature/*",
"refs/heads/hotfix/*"
],
"event": {
"include": [
"push",
],
"exclude": [
"tag",
]
},
},
"steps": [],
}
pipeline["steps"].extend(steps)
return pipeline
def secrets(values):
val = []
for content in values:
val.append(
{
"kind": "secret",
"name": content["name"],
"get":
{
"path": content["path"],
"name": content["key"],
}
}
)
return val
def init(ctx):
return {
"name": "initialize",
"image": "alpine",
"commands": [
"echo \"%s\"" % ctx,
]
}