jenkins mask密码在返回关键字的呼叫时公开秘密文本
我使用 jenkins蒙版密码掩盖秘密文本并效果很好。但是,当试图使用返回从单独的方法调用此秘密文本时,它会公开文本。
properties([
parameters([
password(name: 'Passwd', description: 'Encryption key')
])
])
// function of mask text ---
def getAppPassword(){
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'SECRET', password: Passwd]], varMaskRegexes: []]) {
echo "${Passwd}" // here text get mask
return "${Passwd}" //
}
}
// declarative pipeline --
pipeline {
agent any
// setting up as environment varible to access it throught out the file.
environment {
ExecutorPassword = getAppPassword()
}
stages {
stage('Hello') {
steps {
bat "--${ExecutorPassword} "
if ("${ExecutorPassword}" == "12324") {echo "Equal!"}
else{ echo "Mark" };
}
}
}
}
从过去的三天开始,我一直在这里。请帮忙。
在中getapppassword()
函数 echo“ $ {passwd}”
返回一个秘密文本,如 ***
。
但是,当我调用 pipeline
spep bat中的 时, bat” - $ {executorPassword}” 时。它将秘密文字暴露在控制台中。
尝试单引号,两者都引用。
-
使用double Quote
时“
)露出秘密文本。使用 -
When used single quote
'
it returns${ExecutorPassword}
varible as是。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用两种不同的方法,而不是在参数中传递密码。
使用 Jenkins 凭证库,因为它会自动使用 AES 加密来加密您的密码。
使用输入函数在运行构建之间获取密码并将存储密码的变量放在有限的范围内将有助于您的安全,您也可以对其进行屏蔽,然后销毁该变量或将其设置为空你的作品完成了。这是一个小例子。
` if(authType != 'W'){
Instead of passing the password in parameter you can use two different methods.
Use Jenkins credentials vault as it will automatically encrypt your password with AES encryption.
Use input function to get the password in between of running build and putting the variable which store the password in limited scope will help you secure and you can also do masking on it and then destroy the variable or make it null as soon as your works done. Here is a small example.
` if(authType != 'W'){