Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Pipeline: trigger downstream job to run later

I currently have a multibranch project, and I would like the "development" branch build to trigger another top-level Maven Jenkins job. The goals in the multibranch project are kept down to a minimum (build and unit tests), while the top level Maven project is configured to run all kinds of reports ("site site-deploy").

I currently use something like this:

if ("development".equals(branchName)) { stage('Trigger Full Build') { build job: "FullJob" } }

This works as expected, but the disadvantage is that the "build job" step will take up ~40 minutes, which is the time that it taken by the full job. I would like to know if it is possible to trigger the full job from the multibranch job, but allow the full job to run asynchronously (not count against the execution time of the multibranch job)

like image 573
fshehadeh Avatar asked Feb 03 '17 04:02

fshehadeh


People also ask

How do I trigger a Jenkins job after another job?

Use build job plugin for that task in order to trigger other jobs from jenkins file. You can add variety of logic to your execution such as parallel ,node and agents options and steps for triggering external jobs.

How do I schedule a job in Jenkins pipeline?

Add a Schedule to a Jenkins JobHead back to the job configuration and click the Build Triggers tab. Now, check the Build periodically box in the Build Triggers section. This will open the scheduling text area. Next, let's set the job to run every five minutes.


1 Answers

Have a look into the syntax help for the build pipeline step at http(s)://your-jenkins.com/jenkins/pipeline-syntax. Just select the build step, select the parameters you want and press the generate button to get the corresponding snippet.

The shortcut:

The build step does wait for triggered downstream builds by default. But there is the parameter wait that can be set to false, allowing you to fire and forget in your multibranch pipeline:

if( "development" == branchName) {
    stage("trigger full build") {
        build job: 'FullBuild', wait: false
    }
}
like image 57
mawi Avatar answered Oct 12 '22 11:10

mawi