pipeline从credential中获取username和password

法一:

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"

}

法二:

environment {

    BITBUCKET_COMMON_CREDS = credentials('jenkins-bitbucket-common-creds')

}

BITBUCKET_COMMON_CREDS - contains a username and a password separated by a colon in the format username:password.

BITBUCKET_COMMON_CREDS_USR - an additional variable containing the username component only.

BITBUCKET_COMMON_CREDS_PSW - an additional variable containing the password component only.

你可能感兴趣的:(pipeline从credential中获取username和password)