• Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Minor Minor
    • _unsorted
    • Azure Credentials 1.6.0
      Jenkins ver. 2.150.3
      Centos 7.4

      Hello,

      Before, I used Environment variables in Jenkins configuration to set Azure credentials and my terraform init worked.

      I installed the Azure credentials in order to use several tenant credentials.

      but my terraform init complain this:

      Error configuring the backend "azurerm": resource_group_name and credentials must be provided when access_key is absent

      when I set back Environment variables in Jenkins, everything works.

      this is my pipeline script:

       

      ---------------

       
      def checkout() {
      stage('Clone repository') {
      git branch: 'dev',
      credentialsId: 'gitalb-token-ci',
      url: 'https://url.git'
      sh "ls -lat"
      }
      }
       
      def terraformFmt() {
      stage('Terraform fmt') {
      sh 'terraform fmt'
      }
      }

      def terraformInit() {
      stage('Terraform Init') {
      sh "az login --service-principal -u $CLIENT_ID -p $CLIENT_SECRET -t $TENANT_ID"
      sh "az account set -s $SUBS_ID"
      sh "terraform init"
      }
      }

      def terraformPlan() {
      stage('Terraform Plan') {
      sh "terraform plan -input=false"
      }
      }

      def terraformApply() {
      stage('Terraform Apply') {
      input "Are you ready for APPLY ?"
      sh "terraform apply -input=false -auto-approve"
      }
      }
       
      node {
      withCredentials([azureServicePrincipal(credentialsId: 'credentials_id_ci,
      subscriptionIdVariable: 'SUBS_ID',
      clientIdVariable: 'CLIENT_ID',
      clientSecretVariable: 'CLIENT_SECRET',
      tenantIdVariable: 'TENANT_ID')]) {
       
      checkout()
      terraformFmt()
      terraformInit()
      terraformPlan()
      terraformApply()
      }
      ---------------
       
      thanks for your help.

          [JENKINS-56482] custom name variable seems to not working

          Jie Shen added a comment -

          Hi krugg3r, how do you set back Environment variables in Jenkins before? You current problem is that you cannot fetch the variables in the withCredentials block?

          Jie Shen added a comment - Hi krugg3r , how do you set back Environment variables in Jenkins before? You current problem is that you cannot fetch the variables in the withCredentials block?

          Omega BK added a comment -

          Hello jieshe,
          I set Environment variables in Jenkins in global this way:
          Manage Jenkins—> Configure System—> in Global properties—> Environment variables. 
          Then I can add my Azure credentials and there, it works. But this way, I cannot use multiple custom variables for multiple tenants.
          And as you stated, If I remove the global variables, and set through withCredentials block, I’m not able to fetch the variables. 

          however, the service principal test works with the plugin when I put credentials variables.

          Thanks for your help.

          Omega bk

          Omega BK added a comment - Hello jieshe , I set Environment variables in Jenkins in global this way: Manage Jenkins—> Configure System—> in Global properties—> Environment variables.  Then I can add my Azure credentials and there, it works. But this way, I cannot use multiple custom variables for multiple tenants. And as you stated, If I remove the global variables, and set through withCredentials block, I’m not able to fetch the variables.  however, the service principal test works with the plugin when I put credentials variables. Thanks for your help. Omega bk

          Jie Shen added a comment -

          I test below pipeline, it seems to work fine.

           

          def a() {
              stage('Clone repository') {
                 sh '''
                       echo $SUBS_ID
                       echo $CLIENT_ID
                 ''' 
                  
              }
          }
          
          node {
                              withCredentials([azureServicePrincipal(credentialsId: 'jenkins-sp',
                              subscriptionIdVariable: 'SUBS_ID',
                              clientIdVariable: 'CLIENT_ID',
                              clientSecretVariable: 'CLIENT_SECRET',
                              tenantIdVariable: 'TENANT_ID')]) {  
                                  a() 
                              }
          }
          

          Jie Shen added a comment - I test below pipeline, it seems to work fine.   def a() { stage( 'Clone repository' ) { sh ''' echo $SUBS_ID echo $CLIENT_ID ''' } } node { withCredentials([azureServicePrincipal(credentialsId: 'jenkins-sp' , subscriptionIdVariable: 'SUBS_ID' , clientIdVariable: 'CLIENT_ID' , clientSecretVariable: 'CLIENT_SECRET' , tenantIdVariable: 'TENANT_ID' )]) { a() } }

          Omega BK added a comment -

          Hello,
          Backend Azurerm still complains.
          so what I noticed. Globals variables works but restrict usage of multi tenants.
          I found a way to workaround it.
          using credentials secret, passing them to a env.VARIABLE, this works. so I don't use Azure credentials plugin.
          thanks for your time.

          Omega BK added a comment - Hello, Backend Azurerm still complains. so what I noticed. Globals variables works but restrict usage of multi tenants. I found a way to workaround it. using credentials secret, passing them to a env.VARIABLE, this works. so I don't use Azure credentials plugin. thanks for your time.

            jieshe Jie Shen
            krugg3r Omega BK
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: