Search code examples
azurejenkinsazure-devopsjenkins-pipelineazure-cli

Azure login with Jenkins pipeline


I'm trying to login to Azure using Azure Credentials plugin via Jenkins pipeline (Ubuntu 16.04 as Jenkins slave with the latest Azure CLI):

 stage("Pushing to Azure Storage") {
            withCredentials([azureServicePrincipal(credentialsId: 'AzureServicePrincipal',
                                    subscriptionIdVariable: 'SUBS_ID',
                                    clientIdVariable: 'CLIENT_ID',
                                    clientSecretVariable: 'CLIENT_SECRET',
                                    tenantIdVariable: 'TENANT_ID')]) {
        sh 'az login --service-principal -u $CLIENT_ID -p $CLIENT_SECRET -t $TENANT_ID'
    }
}

The results is the following error:

*[PushTest] Running shell script +az login --service-principal -u **** -p **** -t **** /tmp/jenkins/workspace/PushTest@tmp/durable-7425816d/script.sh: 2: /tmp/jenkins/workspace/PushTest@tmp/durable-7425816d/script.sh: az: not found*

script returned exit code 127


Solution

  • The error you posted shows that az not found. It means there is no Azure CLI installed in the Jenkins node where you execute the shell script. So you just need to install Azure CLI in it.