0

I created a freestyle project in Jenkins where I tried to log in azure in a groovy file

#!/usr/bin/env groovy

// Jenkinsfile (Declarative Pipeline)

pipeline {
  agent any



  stages {
    stage('Stage') {
      steps{
          script {
            withCredentials([azureServicePrincipal('withplugin')]) {
            
              sh 'az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID'
              sh 'az account set -s $AZURE_SUBSCRIPTION_ID'        
          }
         }
      }
    }

  }
}

I created the service principal, I can login with "AZ" "sh AZ" "nohup sh AZ" command line but in Jenkins with or without plugin with clear credential or variable

access is denied in my console output

  • az login --service-principal -u **** -p ****-t ****

Access is denied.

I tried 2 days back to basics even nothing work ....

Can anyone could help me out ?

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
jpyp
  • 1
  • 1

1 Answers1

0

I would suggest you to just add an Azure service principal to Jenkins credential and then write an Jenkins pipeline script by having 'withCredentials([azureServicePrincipal('SERVICEPRINCIPALCREDENTIALID')])' and then using 'sh' part to have Azure CLI commands. For more information with regards to it, please refer this Azure document or this Jenkins plugin article or this Jenkins blog.

Source or Related references:

KrishnaG
  • 3,340
  • 2
  • 6
  • 16