Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a Jenkins pipeline to checkout multiple git repos into same job

I'm using the Jenkins Multiple SCM plugin to check out three git repositories into three sub directories in my Jenkins job. I then execute one set of commands to build a single set of artifacts with information and code drawn from all three repositories.

Multiple SCM is now depreciated, and the text recommends moving to pipelines. I tried, but I can't figure out how to make it work.

Here is the directory structure I'm interested in seeing from the top level of my Jenkins job directory:

$ ls Combination CombinationBuilder CombinationResults 

Each of those three sub-directories has a single git repo checked out. With the Multiple SCM, I used git, and then added the "checkout to a subdirectory" behavior. Here was my attempt with a pipeline script:

node('ATLAS && Linux') {     sh('[ -e CalibrationResults ] || mkdir CalibrationResults')     sh('cd CalibrationResults')     git url: 'https://github.com/AtlasBID/CalibrationResults.git'     sh('cd ..')     sh('[ -e Combination ] || mkdir Combination')     sh('cd Combination')     git url: 'https://github.com/AtlasBID/Combination.git'     sh('cd ..')     sh('[ -e CombinationBuilder ] || mkdir CombinationBuilder')     sh('cd CombinationBuilder')     git url: 'https://github.com/AtlasBID/CombinationBuilder.git'     sh 'cd ..'      sh('ls')     sh('. CombinationBuilder/build.sh') } 

However, the git command seems to execute at the top level directory of the workspace (which makes some sense), and according to the syntax too, there doesn't seem to be the checkout-to-sub-directory behavior.

like image 369
Gordon Avatar asked Oct 24 '16 17:10

Gordon


People also ask

Can we use multiple Git repos in a single Jenkins job?

Checking out more than one repo at a time in a single workspace is possible with Jenkins + Git Plugin (maybe only in more recent versions?). In section "Source-Code-Management", do not select "Git", but "Multiple SCMs" and add several git repositories.


1 Answers

You can use the dir command to execute a pipeline step in a subdirectory:

node('ATLAS && Linux') {     dir('CalibrationResults') {         git url: 'https://github.com/AtlasBID/CalibrationResults.git'     }     dir('Combination') {         git url: 'https://github.com/AtlasBID/Combination.git'     }     dir('CombinationBuilder') {         git url: 'https://github.com/AtlasBID/CombinationBuilder.git'     }      sh('ls')     sh('. CombinationBuilder/build.sh') } 
like image 100
Wilco Greven Avatar answered Sep 29 '22 14:09

Wilco Greven