当密码属性定义在Jenkinsfile
:
properties([
parameters([
password(name: 'KEY', description: 'Encryption key')
])
])
每次执行管道时,Jenkins 都会提示用户提供其值:
我希望这个参数被屏蔽,以便echo ${KEY}
不打印用户传递的实际值。然而,目前回显它会逐字打印提供的值:
properties([
parameters([
password(name: 'KEY', description: 'Encryption key')
])
])
node {
stage('Stage 1') {
# Will print the actual value of the KEY, verbatim
sh "echo ${KEY}"
}
}
此外,掩码密码插件似乎不适用于 Jenkins 管道,因此不能选择使用它。
有没有办法在构建日志中屏蔽这些密码类型的参数?
你会想要使用屏蔽密码插件 https://wiki.jenkins.io/display/JENKINS/Mask+Passwords+Plugin。这是一个Jenkinsfile
例子取自我的共享管道库 https://github.com/samrocketman/jervis/blob/6cad1f74d021ad5639405dcfc0d79f7c1911eabe/vars/buildViaJervis.groovy#L114-L118.
properties([
parameters([
password(name: 'KEY', description: 'Encryption key')
])
])
node {
stage('Stage 1') {
// Will print the masked value of the KEY, replaced with ****
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'KEY', password: KEY]], varMaskRegexes: []]) {
sh "echo ${KEY}"
}
}
}
除了现有的建议之外withCredentials
,没什么可补充的。但是,如果您通过模板自动生成作业并设置默认密码,那么您可能需要使用hudson.util.Secret
以保护您的模板。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)