我有一条管道,并行运行一系列不同的测试。有时其中一个测试失败,我只想重新启动该测试。在使用管道之前,我使用了矩阵重定向插件来实现这一点。我想用管道实现同样的目标,我相信实现这一目标的一种方法是通过构建参数。
我有以下管道:
pipeline {
agent any
parameters {
booleanParam(name: 'RUBY_LINUX', defaultValue: true, description: 'Ruby unit tests on Linux')
booleanParam(name: 'RUBY_MACOS', defaultValue: true, description: 'Ruby unit tests on macOS')
}
stages {
stage('test') {
steps {
parallel(
'Ruby unit tests on Linux': {
node('linux') {
if (params.RUBY_LINUX) {
echo 'Ran test.'
} else {
echo 'Skipped test.'
}
}
},
'Ruby unit tests on macOS': {
node('macos') {
if (params.RUBY_MACOS) {
echo 'Ran test.'
} else {
echo 'Skipped test.'
}
}
}
)
}
}
}
}但这给了我一个错误:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 24: Expected a step @ line 24, column 13.
if (params.RUBY_LINUX) {
^
WorkflowScript: 41: Expected a step @ line 41, column 13.
if (params.RUBY_MACOS) {
^我怎么才能解决这个问题?
发布于 2017-05-12 13:16:43
如果要在声明性管道语法中使用Groovy表达式,可以使用脚本步骤,也可以切换到脚本管道。
有关语法比较,请参阅以下链接:https://jenkins.io/doc/book/pipeline/syntax/
下面的代码通过在脚本步骤中包装并行部分来修复您的问题:
...
stages {
stage('test') {
steps {
script {
parallel(
'Ruby unit tests on Linux': {
node('linux') {
if (params.RUBY_LINUX) {
echo 'Ran test.'
} else {
echo 'Skipped test.'
}
}
},
'Ruby unit tests on macOS': {
node('macos') {
if (params.RUBY_MACOS) {
echo 'Ran test.'
} else {
echo 'Skipped test.'
}
}
}
)
}
}
}
}
...https://stackoverflow.com/questions/43933311
复制相似问题