How to hide passwords in Jenkins console output? How to hide passwords in Jenkins console output? shell shell

How to hide passwords in Jenkins console output?


Tested with Jenkins 1.609.1 and Mask Passwords Plugin 2.7.3. You need to activate it in the "Configure System" and also in the job you want to use this. In the job configuration is a point "Mask passwords" which must be activated and then will use the global config to mask passwords.


in case that you have a Linux builder you can hide the output of the shell commandunder the execute shell in the command text box just add in the first line the line:

#!/bin/bash +xsome other commands...

this will hide only the output of the command with the password in the console output


You can use credentials. Add secret text credentials and give and id that you'll use like the following:

          withCredentials([string(credentialsId: 'DOCKER_USER', variable: 'DOCKER_USER'), string(credentialsId: 'DOCKER_PASSWORD', variable: 'DOCKER_PASSWORD')]) {            sh "docker login -u $DOCKER_USER -p $DOCKER_PASSWORD"            sh "docker push '$DOCKER_USER/appName:test'"           }

DOCKER_USER AND DOCKER_PASSWORD are in the jenkins credentials store and will be replaced by *** in the logs