作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个像这样的 Jenkins 常规脚本:
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 中勾选或取消勾选 bool 参数,ARGS 的值始终为“--p b1 ---p b2 --p b3”。这意味着 shell 脚本中存在的三个 if 将始终被评估为 true。为什么会出现这种情况?
最佳答案
参数可从 env
和 params
获取。当您以 $b1
身份访问它们时,您将从 env
获取它们,而不是 params
。
所有环境变量本质上都是字符串,因此当您将参数作为环境变量访问时,它们始终字符串。
如果您想在键入时访问它们,请使用params
:
script {
assert env.b1 instanceof String
assert params.b1 instanceof Boolean
}
关于jenkins - jenkins dsl 中的 booleanParam,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40854732/
我有一个像这样的 Jenkins 常规脚本: freeStyleJob(“test”) { properties { githubProjectUrl(‘…’) }
我是一名优秀的程序员,十分优秀!