Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define jenkins build trigger in jenkinsfile to start build after other job

I would like to define a build trigger in my Jenkinsfile. I know how to do it for the BuildDiscarderProperty:

properties([[$class: 'jenkins.model.BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '50', artifactNumToKeepStr: '20']]])

How can I set the Build Trigger that starts the job, when another project has been built. I cannot find a suitable entry in the Java API docs.

Edit: My solution is to use the following code:

stage('Build Agent'){
  if (env.BRANCH_NAME == 'develop') {
    try {
        // try to start subsequent job, but don't wait for it to finish
        build job: '../Agent/develop', wait: false
    } catch(Exception ex) {
        echo "An error occurred while building the agent."
    }
  }
  if (env.BRANCH_NAME == 'master') {
    // start subsequent job and wait for it to finish
    build '../Agent/master', wait: true
  }
}
like image 663
user2131878 Avatar asked Oct 09 '16 14:10

user2131878


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 trigger a build automatically in Jenkins?

Follow the steps as mentioned below to trigger a Jenkins job automatically based on GitHub's webhook configurations: Step 1: Go to the Configuration page of the respective job and under the build trigger section, check the "GitHub hook trigger for GITScm polling" checkbox and click on the Save button.


1 Answers

I just looked for the same thing and found this Jenkinsfilein jenkins-infra/jenkins.io

In short:

properties([
    pipelineTriggers([cron('H/30 * * * *')])
])
like image 177
Niklaus Bucher Avatar answered Oct 23 '22 03:10

Niklaus Bucher