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

半世苍凉 提交于 2021-02-16 18:07:56

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/41182186/jenkins-pipeline-with-folder-plugin-how-to-build-a-job-located-different-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!