Using Azure-Cli to deploy an azure function to azure from Jenkins

1k Views Asked by At

I have created a docker container and generated final artifact of my azure function app code. Azure Cli is already installed in the container. Is it possible to deploy to Azure using Azure Cli and pass the credentials along?

I tried the following command (example credentials):

az functionapp deployment user set --user-name "MY_USER" --password "MY_PASS" --subscription "MY_SUBSCRIPTION"

But it results in the following error:

Subscription 'MY_SUBSCRIPTION' not recognized. ValidationError: Please run 'az login' to setup account.

If I login (which requires entering a pass code to a browser), then the command above seems to be working.

This is going to be part of CI/CD and manual login is not a solution. Any ideas?

2

There are 2 best solutions below

0
On BEST ANSWER

You would need to use a service principle to authenticate. But since you mentioned you are using Jenkins, fortunately there are rich set of plugins available for different Azure resources which can handle the authentication for you if you setup in your Jenkins dashboard. For example, in this case you are using az cli for which you can install https://plugins.jenkins.io/azure-cli/

0
On

Yes, you need to be authenticated. Here you have several authentication options: Sign in with Azure CLI

Authenticating with a service principal is the best way to write secure scripts or programs

Sign in with a service principal