Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Please check this official guide to see if you have defined it correctly.

Also check if you're passing credentials ID, not a description to credentials() method.

If you're using Jenkins pipelines, you also can try Credentials Binding Plugin . From plugin wiki , a typical example of a username password type credential would look like:

withCredentials([usernamePassword(credentialsId: 'amazon', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
  // available as an env variable, but will be masked if you try to print it out any which way
  // note: single quotes prevent Groovy interpolation; expansion is by Bourne Shell, which is what you want
  sh 'echo $PASSWORD'
  // also available as a Groovy variable
  echo USERNAME
  // or inside double quotes for string interpolation
  echo "username is $USERNAME"

For scripted pipeline you can use withCredentials() as well (see this):

node {
  withCredentials([usernameColonPassword(credentialsId: 'mylogin', variable: 'USERPASS')]) {
    sh '''
      set +x
      curl -u "$USERPASS" https://private.server/ > output

Or you can use withEnv() section:

node {
    withEnv(["CREDS=credentials('jenkins-creds')"]) {
        stage('Build') {
            sh 'printenv'
                def GOOGLE_CREDENTIALS = credentials('XYZ credentials') sh 'echo ****** $GOOGLE_CREDENTIALS ****' This is not working
– Shubham Singh
                Dec 26, 2018 at 11:44
                Did you use credentials() method in the environment directive? (See this). E.g.,        environment {         BITBUCKET_COMMON_CREDS = credentials('jenkins-bitbucket-common-creds')     }
– biruk1230
                Dec 26, 2018 at 14:43
                Or, probably, you're passing credentials description to credentials() method, not a credential ID. In that case, you must specify ID of your credentials.
– biruk1230
                Dec 26, 2018 at 14:51
                If you're using node, it's called scripted pipeline. So, for scripted pipeline you can use withCredentials() or withEnv() section (updated in answer).
– biruk1230
                Dec 27, 2018 at 10:07
node { 
    stage('Preparing env') {
        withCredentials([usernamePassword(credentialsId: 'XYZ Credentials', passwordVariable: 'GOOGLE_CREDENTIALS_PSW', usernameVariable: 'GOOGLE_CREDENTIALS_USR')]) {
            // Do something here with your username and password variables
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.