Note: The password value needs to be in the above format, e.g. ( “$NEW_PASSWORD”) and the var value needs to be your password variable name, e.g. (“NEW_PASSWORD”).
Reason: The mask plugin checks the variable used in the pipeline by var value and masks the password by password value which we dynamically generate.
-> Here NEW_PASSWORD is the password variable which I need to mask, replace it with your value, and save.
-> Here is the pipeline example which adds a user without the shell access in the Linux instance
pipeline{agent{node{label'gcp'}}stages{stage('User Creation') {steps{script{// Password GeneratorNEW_PASSWORD=sh(script: 'openssl passwd -crypt password',returnStdout: true ).trim()env.NEW_PASSWORD=NEW_PASSWORDmaskPasswords(varMaskRegexes: [],varPasswordPairs: [[password: "$NEW_PASSWORD",var: 'NEW_PASSWORD']]) {sh''' # User creationuseradd-s/sbin/nologin"$NEW_USERNAME" [ $?-eq0 ] &&echo"User has been added to system!"||echo"Failed to add a user!" # Settingthepasswordfortheuserecho"$NEW_USERNAME:$NEW_PASSWORD"|chpasswdecho"User password has been created" # Checkifpasswordchangewassuccessfulif [ $?-eq0 ]; thenecho"Password has been set for the user!"elseecho"Failed to set the password."fi''' } } } } } }
-> Run the pipeline and after the pipeline is completed check the logs, where your password is masked