By Brendo Ross
Hi all,
It’s been a long time since I last posted a question here but I’m back! :D
Anyway, I’m currently trying some stuff with Jenkins and I’ve started creating a small project. I have an issue where I have 3 repositories (Jenkinsfile, script and some additional libraries) which I want to include in my pipeline.
I’m using SCM and my Jenkinsfile is in one of the repositories.
So far all my attempts have failed. Here is what I have:
node {
stage 'prepare'
checkout scm
and I am defining the Jenkinsfile repo in the job configuration.
So what I would like to do is check out all three repositories, then use the Jenkinsfile to use the rest.
Anyone has any suggestions?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Hi @brendRos,
I think in your case the RelativeTargetDirectory plugin of the GitSCM class should help. You can read more about it here:
Or here
When you open the Jenkins Documentation(above link) select - $class: ‘GitSCM’ and then inside you’ll be able to find $class: ‘RelativeTargetDirectory’
$class: 'RelativeTargetDirectory'
relativeTargetDir
Specify a local directory (relative to the workspace root) where the Git repository will be checked out. If left empty, the workspace root itself will be used.
Type: String
Here is an example of how to use it
stages {
stage('GitCheckout') {
steps {
checkout \
scm: [ $class : 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'subdirectory2']], submoduleCfg: [], userRemoteConfigs: [[url: 'repo2.git']]])]
}
}
}
Please remember to change the relativeTargetDir - subdirectory2 in this case to the one you want.
Additionally, in userRemoteConfigs: [[url: ‘repo2.git’]]] add your actual git repo.
Regards, KFSys
Hi @brendRos,
I’m starting a new thread/answer just because the previous one became too long and it might be confusing to read afterwards.
I’m going to try and answer to both question in a single code block. The code block will include both a better readable syntax and how to post multiple Git Repositories to be checked out:
stages {
stage('GitCheckout') {
steps {
checkout \
scm: [ $class : 'GitSCM', \
branches: [[name: '*/master']], \
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'subdirectory1']],
[ $class: 'ScmName', name: 'subdirectory1' ]], \
userRemoteConfigs: [[ \
url: 'repo1.git' \
]]
]
]
checkout \
scm: [ $class : 'GitSCM', \
branches: [[name: '*/master']], \
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'subdirectory2']],
[ $class: 'ScmName', name: 'subdirectory2' ]], \
userRemoteConfigs: [[ \
url: 'repo1.git' \
]]
]
]
}
}
}
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.