Jenkins credentials

environment {
MAGE_REPO_CREDENTIALS = credentials('COMPOSER_REPO_MAGENTO')
COMPOSER_AUTH = """{
  "http-basic": {
      "repo.magento.com": {
          "username": "${env.MAGE_REPO_CREDENTIALS_USR}",
          "password": "${env.MAGE_REPO_CREDENTIALS_PSW}"
      }
  } }"""
}

  

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"
}

Reference

https://www.cnblogs.com/FLY_DREAM/p/13888423.html

原文地址:https://www.cnblogs.com/i-shu/p/14817860.html