【发布时间】:2017-04-12 18:59:01
【问题描述】:
我有一个这样的 jenkins groovy 脚本:
freeStyleJob(“test”) {
properties { githubProjectUrl(‘…’) }
description(‘’’job description’’’.stripMargin('|'))
logRotator{ numToKeep(100) }
parameters {
stringParam(’STRINGP1’, "", “STRINGP1 description”)
stringParam('STRINGP2’, "", “StringP2 description”)
booleanParam(‘b1’, false)
booleanParam(‘b2’, false)
booleanParam(‘b3’, false)
stringParam("EMAIL_LIST", "", "Emails")
}
scm {
github(‘repo’, '${STRINGP1}', 'git', ‘giturl’)
}
steps {
shell '''|#!/bin/bash
|ARGS=""
|fi
|if [[ ‘${b1}’ ]]; then
| ARGS=$ARGS" —-p b1”
|fi
|if [[ ‘${b2}’ ]]; then
| OS_ARGS=$ARGS" —-p b2”
|fi
|if [[ ‘${b3}’ ]]; then
| ARGS=$ARGS" —-p b3”
|fi
|echo ${ARGS}'''.stripMargin('|')
}
publishers {
archiveArtifacts {
pattern(‘pattern’)
}
extendedEmail {
....
}
}
}
....
}
创建作业后,无论用户是否选中或取消选中 UI 中的布尔参数,ARGS 的值将始终为“--p b1 ---p b2 --p b3”。这意味着如果 shell 脚本中存在这三个,则将始终评估为 true。为什么会这样?
【问题讨论】: