如何在运行Jenkins CI管道时屏蔽作为用户输入传递的密码?

问题描述 投票:0回答:1

在Jenkins的早期版本中,我已经看到我们在作业中添加了“密码参数”,当用户在运行作业时将值传递给它时,它不会显示字符,而是会被屏蔽。他们还会在工作建设历史中被掩盖。

我在Jenkins CI管道中有相同的要求,在jenkinsfile中我可以提到一个参数,需要在用户输入到python片段时将其作为掩码传递。我确实通过了文档,其中允许的params类型也有“密码”,但我不认为它的行为符合我的要求。有人可以用正确的语法或任何其他方式帮助我吗?

python jenkins jenkins-pipeline
1个回答
1
投票

如果您运行以下管道:

pipeline {
    agent any 
    stages {
        stage('Build') { 
            steps {
                withCredentials([usernameColonPassword(credentialsId: 'dummy', variable: 'USER_AND_PASS')]) {
                    sh '''
                        echo "The credential is ${USER_AND_PASS}"
                    '''
                }
            }
        }
    }
}

您将看到在构建输出中屏蔽了用户名和密码

© www.soinside.com 2019 - 2024. All rights reserved.