Lam*_*bda 5 jenkins jenkins-plugins jenkins-pipeline
当在中定义密码属性时Jenkinsfile:
properties([
parameters([
password(name: 'KEY', description: 'Encryption key')
])
])
Run Code Online (Sandbox Code Playgroud)
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}"
}
}
Run Code Online (Sandbox Code Playgroud)
同样,Mask Passwords插件似乎无法与Jenkins管道一起使用,因此不能使用它。
有没有办法在构建日志中屏蔽这些密码类型的参数?
您将要使用掩码密码插件。这是我的共享管道库中的Jenkinsfile示例。
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}"
}
}
}
Run Code Online (Sandbox Code Playgroud)
除了上的现有建议外withCredentials,没有太多补充。但是,您要通过模板自动生成作业,并且要设置默认密码,那么您可能想利用它hudson.util.Secret来保护模板。
您可以使用Jenkins Credentials 插件。通过此插件,您可以创建一个带有 ID 的凭证以在管道中使用:
代码将是:
withCredentials([string(credentialsId: 'pass', variable: 'password1')]) {
echo "My password is '${password1}'!"
}
Run Code Online (Sandbox Code Playgroud)
在您的用户案例中:
node {
stage('Echo') {
withCredentials([string(credentialsId: 'pass', variable: 'password1')]) {
echo "'${password1}'!"
}
}
}
Run Code Online (Sandbox Code Playgroud)
注意:密码仅在 withCredentials 块中被屏蔽。
| 归档时间: |
|
| 查看次数: |
9833 次 |
| 最近记录: |