gpt4 book ai didi

jenkins - jenkins dsl 中的 booleanParam

转载 作者:行者123 更新时间:2023-12-02 16:44:43 24 4
gpt4 key购买 nike

我有一个像这样的 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。为什么会出现这种情况?

最佳答案

参数可从 envparams 获取。当您以 $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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com