Jenkins : use withCredentials in global environment section

后端 未结 4 1506
星月不相逢
星月不相逢 2021-02-13 01:58

I have a Jenkins pipeline with multiple stages that all require the same environment variables, I run this like so:

script {
    withCredentials([usernamePasswor         


        
4条回答
  •  孤独总比滥情好
    2021-02-13 02:28

    You can use credentials helper method of the environment section. For "Username and passwrd" type of credentials it assigns 2 additional environment variables. Example:

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

    Read more

提交回复
热议问题