我想使用带有声明性管道的上述插件,确切地说,我想将以下文档示例转换为声明性管道:
上游作业中的管道代码如下:
stage ('Stage 1. Allocate workspace in the upstream job')
def extWorkspace = exwsAllocate 'diskpool1'
node ('linux') {
exws (extWorkspace) {
stage('Stage 2. Build in the upstream job')
git url: 'https://github.com/alexsomai/dummy-hello-world.git'
def mvnHome = tool 'M3'
sh '${mvnHome}/bin/mvn clean install -DskipTests'
}
}
下游的管道代码是:
stage ('Stage 3. Select the upstream run')
def run = selectRun 'upstream'
stage ('Stage 4. Allocate workspace in the downstream job')
def extWorkspace = exwsAllocate selectedRun: run
node ('test') {
exws (extWorkspace) {
stage('Stage 5. Run tests in the downstream job')
def mvnHome = tool 'M3'
sh '${mvnHome}/bin/mvn test'
}
}
谢谢!
答案 0 :(得分:1)
我到处搜索有关此问题的明确答案,但从未找到明确的答案。因此,我提取了外部工作区插件代码并阅读了。只要插件的Model不变,答案就很简单。
Anytunc的答案非常接近,但问题是从“外部工作区”插件获取路径并将其进入customWorkspace配置。
我最终要做的是创建一个方法:
def getExternalWorkspace() {
extWorkspace = exwsAllocate diskPoolId: "jenkins"
return extWorkspace.getCompleteWorkspacePath()
}
并将我的代理设置为:
agent {
node {
label 'Linux'
customWorkspace getExternalWorkspace()
}
}
如果您不想将整个管道设置为该路径,则可以根据需要创建任意数量的外部工作区,然后使用
...
steps {
dir(getExternalWorkspace()) {
do fancy stuff
...
}
}
...
答案 1 :(得分:0)
您可以使用以下代理指令:
agent {
node {
label 'my-defined-label'
customWorkspace '/some/other/path'
}
}