Using Azure CLI in Jenkins pipeline

11.3k views Asked by At

I'm trying to use the Jenkins pipeline with Azure using this tutorial: https://learn.microsoft.com/en-us/azure/jenkins/execute-cli-jenkins-pipeline with the exception that I have Jenkins on localhost (running Win7).

The build works as expected, but deployment fails on the line in Jenkinsfile where the 'az login...' script should run, with a 'command not found' error.

 withCredentials([azureServicePrincipal('...')]) {
      sh '''
        'az login ..'

I am able to use the 'az' commands in the command line outside of Jenkins.

Am I missing something? Any help would be appreciated.

1

There are 1 answers

19
Shui shengbao On BEST ANSWER

You need to add Azure service principal to Jenkins credential. Please refer to the link you provided.

If you don't have a service principal, you could use Azure CLI 2.0 to create a new. Please refer to this link:Create an Azure service principal with Azure CLI 2.0.

withCredentials([azureServicePrincipal('<mySrvPrincipal>')]) 

<mySrcvPrincipal> is credential id you set.

enter image description here

Note:

When you add Azure service principal to Jenkins credential, click Verify Service Principal, please ensure you also see Successfully verified the Microsoft Azure Service Principal.