带有文件夹插件的Jenkins管道.如何建立位于不同文件夹的作业 [英] Jenkins pipeline with folder plugin. How to build a job located different folder
问题描述
我正在将 jenkins 2.0 与Cloudbees Folder插件配合使用,因为这使我可以创建多个类似的项目.可以将每个文件夹中的作业排除在外,留下一个顶层作业,然后可以调用该作业来进行参数设置.
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.
因此在jenkins浏览器中,我将拥有3个文件夹:ProjA,ProjB和Generic.在ProjA下,我有一个管道作业,需要在通用文件夹中构建一个名为TestJib的作业.
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.
我的管道是这样的:
node('master'){
stage ('Run job'){
build job: "../Generic/TestJob",
parameters: [[$class: 'StringParameterValue', name: 'testa', value: tests]]
}
}
运行此命令将得到:'错误:没有名为../TestJob的参数化作业'
我在构建作业上尝试了许多变体:"../Generic/TestJob",但是我总是遇到相同的错误. 如果将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.
推荐答案
您只需要将文件夹设置为不带斜杠即可.
You have only to set the folder without slash before.
如果文件夹FolderA中有JobA,则您的工作将类似于:
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.
这篇关于带有文件夹插件的Jenkins管道.如何建立位于不同文件夹的作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!