Azure CLI not found in Jenkins - azure

I have install azure cli plugins in jenkins after that i setup Azure Service Principal and got Successfully verified the Microsoft Azure Service Principal after that i create a new job and added az version to check az is installed or not in it and got failed error below is the screenshot of that error
Note:- My Jenkins is having v2.332.1 and installed in AKS Cluster as a Helm chat my jenkins is running
Here is the screenshot of plugin installed
Here is the my job new create in freestylejob
Please help out with this issue

You need to install azure cli in the Jenkins Host as well.
from
https://plugins.jenkins.io/azure-cli/ - Prerequisites
To use this plugin, first you need to have an Azure Service Principal
in your Jenkins instance.
1.Create an Azure Service Principal through Azure CLI or Azure portal.
2.Open Jenkins dashboard, go to Credentials, add a new Microsoft Azure Service Principal with the credential information you just created.
3.Install Azure CLI in the Jenkins Host
from your description, I can see you have 1,2 steps completed and possibly 3 is missing.

Related

do you need to login - using `az devops login` - when AZURE_DEVOPS_EXT_PAT is set?

Do I still need to login using az devops login in cli to work on Azure DevOps when I already have PAT set using environment variable?
I tried the code below on three workstations but it keeps failing on third workstation:
Ubuntu running in Azure
Ubuntu running locally in the container in my laptop
WSL (Ubuntu) running locally in my laptop
export AZURE_DEVOPS_EXT_PAT=******************
organization="https://dev.azure.com/myorg/"
az devops project list --organization $organization
Note that I am able to retrieve the project list from the first two "workstations" without invoking az devops login, but unable to retrieve so on my WSL, and I am getting the following error message:
Before you can run Azure DevOps commands, you need to run the login command(az login if using AAD/MSA identity else az devops login if using PAT token) to setup credentials. Please see https://aka.ms/azure-devops-cli-auth for more information.
Any idea of what would contribute to this inconsistency?

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

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?
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/
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

Azure CLI Login within Docker Container

I have successfully created a docker image that runs inside a docker container. The container successfully executes the image (a .NET app) but the image crashes shortly after startup because it encounters an error with Azure Services. The reason is because the docker container is attempting to access Azure Services to fetch an authorization token (to fetch secrets from a key vault) and does not have authority to do so.
I should note that it is possible to run the app locally outside of a container via the Azure CLI after using az login to verify my credentials. Then, when the app is started via Azure CLI, it is 'allowed' to access Azure Services to get autho tokens and consequentially fetch data from my key vault.
Would like to know if there is a way to run an az login script with credentials inside a docker container before the .NET app image executes, so that I can start the application from within the Azure CLI (inside the container) after my credentials have been verified. I have looked through the documentation and have not seen a way to configure something like this.
To use the Azure CLI and login inside the container, you need to install the Azure CLI inside the container, then login with an non-interactive model. I would recommend the service principal. You can take a look at the command:
az login --service-principal -u <app-url> -p <password-or-cert> --tenant <tenant>
For more details, see Create an Azure service principal with Azure CLI. After login, then you can start your application as need.
Here are 2 options which don't require Azure CLI in the container, Azure Managed Identity from within a docker container running locally,
inject an access token into the container using ENV variable
use device authentication flow to obtain an access token
I read this answers a while ago. I was looking for the similar solution but using the service principal. I found that Docker can run Kubernetes and there is AAD-Pod-Identity https://github.com/Azure/aad-pod-identity which can do work for me, but it doesn't work for Docker Kubernetes. I forked their Go repository and make modification for mic component. Now it works for Docker Kubernetes, not sure whether Azure team has plans get these modifications on board or not.
You can get detailed instructions how to get things running here: https://github.com/Wallsmedia/aad-pod-identity
Azure CLI would not work for a Docker, because you have setup Azure CLI and login and then run your application.

Unable to access keyvault from Azure DevOps from a different resource description

I'm attempting to build out my DevOps pipeline to deploy a DataFactory, Databricks Notebooks & Azure Data Warehouse,
I have my resource subscriptions setup for both Dev and Prod. deploying to Prod is more tricky than it seems.
my keyvault has GET/LIST Permissions for both Secret & Keys for the Target DataFactory.
https://learn.microsoft.com/en-us/azure/data-factory/continuous-integration-deployment
I have used the above guide to setup my target data factory in prod - and it is stood up correctly with all the connection strings setup and keyvault permissions set.
but I am stuck on this portion :
Grant permissions to the Azure Pipelines agent The Azure Key Vault
task may fail with an Access Denied error if the proper permissions
aren't present. Download the logs for the release, and locate the .ps1
file with the command to give permissions to the Azure Pipelines
agent. You can run the command directly, or you can copy the principal
ID from the file and add the access policy manually in the Azure
portal. Get and List are the minimum permissions required.
when I deploy my release I get the following error on the KeyVault task :
The specified Azure service connection needs to have Get, List secret management permissions on the selected key vault. To set these permissions, download the ProvisionKeyVaultPermissions.ps1 script from build/release logs and execute it, or set them from the Azure portal
I've added this power shell script ProvisionKeyVaultPermissions.ps1 to my repo and added it to my task but it just runs forever ? unsure if I'm missing something here.
hope this is clear/ please ask for any additional info.
I wonder if it's the DevOps service connection that's missing the permissions.
You can check access policies for the vault from the console. You should see your service connection as an APPLICATION; it needs the GET and LIST privileges as the document your following says. My understanding is that these are privileges for the account that's deploying your code, rather than the account that will run your code.

Using Azure CLI in Jenkins pipeline

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.
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.
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.

Resources