Suyash Gupta
Suyash Gupta

Reputation: 119

How to mask password passed as user input while running Jenkins CI pipeline?

In previous versions of Jenkins, I have seen that we have "Password Parameter" to add in a job where when a user pass a value to that while running the job, it wont display the chars and instead they'll be masked. They'll also shown masked in job build history.

I have the same requirement in Jenkins CI pipeline where in jenkinsfile I can mention a parameter which needs to be passed as masked during user input to a python snippet. I did go through the documentation where types of params allowed also has "password", but I dont think it behaves as per my requirement. Can someone help me with the correct syntax or any other way to do this?

Upvotes: 0

Views: 1223

Answers (1)

Rich Duncan
Rich Duncan

Reputation: 1923

If you run the following pipeline:

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

You'll see that the username and password are masked in the build output

Upvotes: 1

Related Questions