Jenkins pipeline with folder plugin. How to build a job located different folder

Garry picture Garry · Dec 16, 2016 · Viewed 8k times · Source

I'm using jenkins 2.0 with Cloudbees Folder plugin as this allow me to create multiple similar projects. The jobs in each folder can be factored out leaving a top level job that can then call a parameterised job.

I want to place the parameterised job in a Generic folder and then call them from a pipeline script.

So within the jenkins browser I would have 3 folder : ProjA, ProjB and Generic. Under ProjA I have a pipeline job that needs to build a job called TestJib in the generic folder.

My pipeline is like this this :

node('master'){

    stage ('Run job'){ 
        build job: "../Generic/TestJob", 
        parameters: [[$class: 'StringParameterValue', name: 'testa', value: tests]]
    }
}

Running this gives : 'ERROR: No parameterized job named ../TestJob'

I have tried many variations on build job: "../Generic/TestJob" but I always get the same error. This works fine if I put the TestJob in the same folder as the pipeline job.

Answer

Algorys picture Algorys · May 22, 2017

You have only to set the folder without slash before.

If you have a JobA in folder FolderA, your job will look something like:

stage ('My Stage'){ 
    build job: "FolderA/JobA", 
}

So for you, your solution will be:

node('master'){

stage ('Run job'){ 
    build job: "Generic/TestJob", 
    parameters: [[$class: 'StringParameterValue', name: 'testa', value: tests]]
  }
}

No matter where your job is located, you just need to indicate the full path.