Home > front end >  Retry downstream jenkins job if tag doesn't exist
Retry downstream jenkins job if tag doesn't exist

Time:11-23

I have Jenkins job (let's call it DeployJob) which triggers another Jenkins job (let's call it BuildJob) both using declarative pipelines.

  build job: "BuildJob/${buildConfig.deployConfig.tag}", parameters: [
    [$class: 'BooleanParameterValue', name: 'DEPLOY',             value: true]
  ]

In DeployJob, buildConfig.deployConfig.tag contains a tag in the repository of BuildJob which may not have been discovered yet, either because the hook has not been processed yet, or because the Scan Multibranch Pipeline service has not yet run.

Is there a mechanic that allows me to either trigger the Scan Multibranch Pipeline of the Repository behind BuildJob? or to wait for (or retry later) if the tag (hence the job) is not found?

CodePudding user response:

Yes, you can, you should be able to use the retry directive here. Here is a Pipeline with some retry logic.

pipeline {
    agent any
    stages {
    stage("A"){
        steps{
            script {
                retry(count: 3) {
                     sleep 60
                     build job: "BuildJob/${buildConfig.deployConfig.tag}", wait: false, parameters: [
    [$class: 'BooleanParameterValue', name: 'DEPLOY', value: true]
  ]                    
                    }
                }
            }
        }
    }
}
  • Related