1

I have three separate Multibranch pipeline jobs set up on Jenkins, which I want to be called sequentially as downstream-jobs. Please note that, all these 3 jobs have separate git repositories!

Each job has its own Jenkinsfile.

The first job is always triggered manually by me through the Jenkins UI. At the last stage of the 1st job's Jenkinsfile, the second job is being triggered, as shown below. (The second job triggers the third job, in the same way)

stage('Trigger second job')
{
   steps {
       build job: 'second_job_name', propagate: true, wait: false
   }
}

Now this step always seems to be executed successfully when the first job ends, no errors or warnings show up on the logs. This should mean that the second downstream job has been called, but unfortunately that's not always the case:

  • Sometimes the first job triggers the second job, but the second job never actually triggers the third one, although it seems to pass the corresponding Jenkinsfile stage.
  • Sometimes the first job completes but never triggers the second job at all.

The only time this setup works as expected, is when there are new commits to all 3 git repos. Then all 3 jobs are triggered sequentially without issues.

Does anyone know the reason behind this inconsistent behavior? Is it maybe because the jobs are based on different git repos? Is there anything I can do to fix this?

Thanks

0

1 Answer 1

1

I suspect this job name is the issue:

build job: 'second_job_name'

In a Multibranch pipeline, there are typically folders in the job name. For instance, if you have a Multibranch project named "my_project", a repo in that project named "my_repo", and a branch within that repo that you wish to build, let's say "master", then your build command would look like:

build job: 'my_project/my_repo/master'

If you only specify up to the project or repo level in your job name, but don't include the branch, instead of running a build for the branch, Jenkins will scan for updates to all branches within that project/repo, and build any new commits which it hasn't yet built. This results in exactly the symptoms you described:

The only time this setup works as expected, is when there are new commits to all 3 git repos. Then all 3 jobs are triggered sequentially without issues.

1
  • Adding the branch i.e. build job: my_project_name/master actually seems to have solved the problem. Thanks a lot!
    – pats
    Mar 31, 2021 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.