Detect the git repo for multi-branch pipeline

48 views
Skip to first unread message

Phil Swenson

unread,
Sep 9, 2016, 1:15:03 PM9/9/16
to Jenkins Users
Hi, I have a multi branch pipeline configuration job working fine so far....

However every single repository has exactly the same jenkinsfile except for the git repo name.

a typical jenkinsfile looks like:

node('docker-slave') {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'NEXUS', usernameVariable: 'NEXUS_USERNAME', passwordVariable: 'NEXUS_PASSWORD']]) {
git url: 'g...@bitbucket.org:myco/myprob.git', branch: env.branch_name, credentialsId: '08df8ab41de0', variable: 'CREDENTIALS'
stage 'Test'
sh 'env > env.txt'
sh 'cat env.txt'
sh 'make verify'
}
}

What I'd like to do is detect which git repo triggered the build so I don't have to hardcode it in the jenkinsfile.  


So what I'd like is to change the git line to something like:

 git url: env.GIT_URL, branch: env.branch_name, credentialsId: '08df8ab41de0', variable: 'CREDENTIALS'


This gets me closer to my eventual goal of storing my Jenkinsfile in a common location instead of having to copy it repo to repo and modify it repo to repo.

Any ideas?

Thanks
phil

Sverre Moe

unread,
Sep 12, 2016, 2:10:09 AM9/12/16
to Jenkins Users
Use instead
checkout scm

It will checkout code from the repository

Phil Swenson

unread,
Sep 13, 2016, 10:52:37 AM9/13/16
to Jenkins Users
Thanks, worked great!
Reply all
Reply to author
Forward
0 new messages