Reputation: 135
I can invoke a simple Jenkins pipeline from gitlab merge requests using a webhook. Now I'd like to know what is the source branch to make the checkout against it. Example: if I push code to develop branch, in my pipeline script i'd checkout develop branch. Thanks.
node {
stage('Build') {
def mybranch = '?' // get branch name from gitlab webhook
git branch: mybranch,
credentialsId: 'mycredential',
url: 'myurl'
// ...
}
}
Upvotes: 2
Views: 5060
Reputation: 680
You can get the current branch name via env.gitlabBranch
.
Reference: gitlab-plugin
Upvotes: 3
Reputation: 86
GitLab plugin creates a lot of useful environment variable. You can see them in here. I think the one you need is CI_COMMIT_REF_NAME
Upvotes: 1