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

1

6

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.

Valery answered 16/12, 2016 at 10:23 Comment(1)
Have you tried an absolute path, i.e. /Generic/TestJob?Mouthpiece
M
10

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.

Marvin answered 22/5, 2017 at 12:44 Comment(2)
is the folder path relative to the job that is accessing it? can you do ../otherfolder/jobnameDarin
@Darin yup it's relative unless it starts with /Shrewmouse

© 2022 - 2024 — McMap. All rights reserved.