0

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

19 Comments

I apologize for not mentioning it, but I did add the service principal as the very first thing (following the tutorial).
@EyfI Do you check the console log, do you find az login --service-principal -u **** -p **** -t ****?
You could login on Jenkins VM with the same command. It should work. I test in my lab, it works for me.
The console shows ../script.sh: line 3: 'az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID: command not found' I logged in on my machine using the interactive login (only running az login and following the steps through the browser) but it didn't help.
@EyfI No, you should login with non-interactive login. Replace $AZURE_CLIENT_ID and $AZURE_CLIENT_SECRET to your value. You add it to the screenshot. I guess the root reason for your issue is your service principal does not have right permission. I suggest you could try.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.