Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRONE_COMMIT_BRANCH refers to target, not source branch in merge requests #11

Closed
based64god opened this issue Feb 6, 2019 · 10 comments
Closed

Comments

@based64god
Copy link

Type:
Bug report. I have a single drone instance running hooked up to a gitlab server via webhooks.

What happened:
Both https://docs.drone.io/reference/environ/drone-commit-branch/ and https://docs.drone.io/reference/environ/drone-branch/ refer to the target branch in builds triggered by merge requests.

Expected:
Both https://docs.drone.io/reference/environ/drone-commit-branch/ and https://docs.drone.io/reference/environ/drone-branch/ should refer to the source branch, while https://docs.drone.io/reference/environ/drone-target-branch/ should refer to the target.

I suspect this is a gitlab issue, and is probably not reproducible on github.

@bradrydzewski
Copy link
Member

Hmmm, I am unable to reproduce this issue (drone 1.0.0-rc.5). The mapping of source and target branch for merge request for GitLab can be found here:
https://github.com/drone/go-scm/blob/master/scm/driver/gitlab/webhook.go#L244:L245

@bradrydzewski bradrydzewski transferred this issue from harness/gitness Feb 6, 2019
@based64god
Copy link
Author

image
Here's a screenshot of the build log. I don't see this for builds triggered by pushes. It's only for ones triggered by merge events. Are there any logs I can push up here that might be useful?

@based64god
Copy link
Author

Small update.
image
Appears to be working as intended.

@based64god
Copy link
Author

For anyone who finds this in the future, you want DRONE_SOURCE_BRANCH.

@quantonganh
Copy link

@bradrydzewski So, we agree that DRONE_COMMIT_BRANCH should refer to source branch (as in 0.8), right?

https://github.com/drone/drone/blob/2a3ffc779ba33a9d9c14ec4faae4cbaac0d898ad/operator/runner/env.go#L85

@bradrydzewski
Copy link
Member

nope, DRONE_COMMIT_BRANCH has always been the target branch, including in 0.8. In 1.0 we also provide more explicit values DRONE_SOURCE_BRANCH and DRONE_TARGET_BRANCH

@quantonganh
Copy link

DRONE_COMMIT_BRANCH has always been the target branch, including in 0.8

I don't think so: https://github.com/drone/drone/blob/768ed784bd74b0e0c2d8d49c4c8b6dca99b25e96/remote/gitlab/gitlab.go#L530

@bradrydzewski
Copy link
Member

bradrydzewski commented Apr 10, 2019

for GitHub and other providers it was target branch. If GitLab were using source branch previously it was a bug. The 1.0 implementation is the desired state.

@quantonganh
Copy link

quantonganh commented Apr 10, 2019

for GitHub and other providers it was target branch.

OK: https://github.com/drone/drone/blob/768ed784bd74b0e0c2d8d49c4c8b6dca99b25e96/remote/github/convert.go#L268

But IMO, it should be source branch, as target branch often is master.

The question is: Is there any env that we can use to refer to the source branch (for both push and pull_request events)?

@bradrydzewski
Copy link
Member

bradrydzewski commented Apr 10, 2019

yes, you can use DRONE_SOURCE_BRANCH for push and pull_request events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants