How to detect jenkins build trigger in jenkinsfile to start building after another work

I would like to define an assembly trigger in mine Jenkinsfile. I know how to do this for BuildDiscarderProperty:

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

How can I set up a Build Trigger that runs a task when another project has been created. 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
  }
}
+4
source share
1 answer

I just searched the same and found this Jenkinsfile in jenkins-infra / jenkins.io

In short:

properties([
    pipelineTriggers([cron('H/30 * * * *')])
])
+3
source

Source: https://habr.com/ru/post/1657199/


All Articles