持续集成 请教 jenkinsfile 中需要根据某个变量值判断是否创建 RobotPublisher 对象,但是放在 script,似乎未能生效

xing.yu · 2018年08月07日 · 最后由 xing.yu 回复于 2018年08月10日 · 1377 次阅读

代码如下
//robotframework excute
stage('robotframework excute'){

steps{
script {
if (penv != "null") {

[$class: 'RobotPublisher',
disableArchiveOutput: false,
logFileName: 'log.html',
otherFiles: '',
outputFileName: 'output.xml',
outputPath: '${WORKSPACE}/report',
passThreshold: 100,
reportFileName: 'report.html',
unstableThreshold: 0]
}

}
}
}

执行日志如下,script 不认识 $class: 'RobotPublisher'好像。但是如果去掉 script{},又会提示 expect a step
[Pipeline] stage
[Pipeline] { (robotframework excute)
[Pipeline] script
[Pipeline] {
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage

共收到 1 条回复 时间 点赞

看了半天的 pipeline 的语法,最后自己摸索到解决办法了,与各位分享一下,加了一个 when 就可以完美解决啦
//robotframework excute
stage('robotframework excute'){
when{
expression{return envFlag != null}
}
steps{
script{
sh "pybot 此处省略"

}
step([$class: 'RobotPublisher',
disableArchiveOutput: false,
logFileName: 'log.html',
otherFiles: '',
outputFileName: 'output.xml',
outputPath: './report',
passThreshold: 100,
reportFileName: 'report.html',
unstableThreshold: 0])
}
}

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册