You can use the build job step from Jenkins Pipeline (Jenkins minimum requirement: 2.130).
Here is the full API for the build phase: https://jenkins.io/doc/pipeline/steps/pipeline-build-step/
How to use build :
job : name of the child job to build. It may be another Pipeline job, but more often it is freestyle or another project.- Use a simple name if the job is in the same folder as the upstream job;
- Instead, you can use relative paths such as
../sister-folder/downstream - Or you can use absolute paths like
/top-level-folder/nested-folder/downstream
Start another job using branch as parameter
At my company, many of our branches include "/". You must replace any instances of "/" with "% 2F" (as specified in the job url).
In this example, we use relative paths.
stage('Trigger Branch Build') { steps { script { echo "Triggering job for branch ${env.BRANCH_NAME}" BRANCH_TO_TAG=env.BRANCH_NAME.replace("/","%2F") build job: "../my-relative-job/${BRANCH_TO_TAG}", wait: false } } }
Start another job using build number as parameter
build job: 'your-job-name', parameters: [ string(name: 'passed_build_number_param', value: String.valueOf(BUILD_NUMBER)), string(name: 'complex_param', value: 'prefix-' + String.valueOf(BUILD_NUMBER)) ]
Run many jobs in parallel
Source: https://jenkins.io/blog/2017/01/19/converting-conditional-to-pipeline/
More information about Parallel here: https://jenkins.io/doc/book/pipeline/syntax/#parallel
stage ('Trigger Builds In Parallel') { steps { // Freestyle build trigger calls a list of jobs // Pipeline build() step only calls one job // To run all three jobs in parallel, we use "parallel" step // https://jenkins.io/doc/pipeline/examples/#jobs-in-parallel parallel ( linux: { build job: 'full-build-linux', parameters: [string(name: 'GIT_BRANCH_NAME', value: env.BRANCH_NAME)] }, mac: { build job: 'full-build-mac', parameters: [string(name: 'GIT_BRANCH_NAME', value: env.BRANCH_NAME)] }, windows: { build job: 'full-build-windows', parameters: [string(name: 'GIT_BRANCH_NAME', value: env.BRANCH_NAME)] }, failFast: false) } }
Or alternatively:
stage('Build A and B') { failFast true parallel { stage('Build A') { steps { build job: "/project/A/${env.BRANCH}", wait: true } } stage('Build B') { steps { build job: "/project/B/${env.BRANCH}", wait: true } } } }
Katie Jul 01 '19 at 19:16 2019-07-01 19:16
source share