Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in DevOps and Agile by (1.5k points)

How to trigger the build of a different job within the Jenkinsfile?

My assumption is that this job is just another repository under same organization, the one which already is having its own Jenkins file.

Also, I want to do this particularly with the master branch, as triggering downstream builds of local branches doesn't make much sense.

Update:

stage 'test-downstream'
node {
     def job = build job: 'some-downtream-job-name'
}

The error I got when executed :

No parameterized job named some-downtream-job-name found

I am confident that this job do exist in jenkins and also under the same folder ( organization) as the present one. It is a different job that is having its own Jenkinsfile.

Please do note that this question is not generic and is specific to the Organization Plugin .

closed

1 Answer

+1 vote
by (7.5k points)
edited by
 
Best answer

First things first, you don't want your upstream executor to be idle by wasting executor slot for wrapping the  build step in node.

Second thing, You could use the environment variable BRANCH_NAME  from a multibranch project for making conditional logic on the current branch.

Thirdly, the parameter "  job " takes an absolute or relative job name. When you assign a name without any path qualification, then it would refer to another job which is in the same folder, (which in multibranch project means another branch of the same repository.)

Thus, what you probably should write is:

if (env.BRANCH_NAME == 'master') { build '../other-repo/master' }

Checkout these Jenkins course , and GitHub training if you wanna learn more about these technologies

Browse Categories

...