Build with Jenkins in Azure

Create an Azure service principal

You need an Azure service principal to create an Azure Container Instances in Azure. You can think of Azure service principal as a ‘user identity’ (login and password or certificate) with a specific role, and tightly controlled permissions to access your resources in Azure.

  1. If you don’t already have an Azure service principal, use Cloud Shell, an interactive, browser-accessible shell for managing Azure resources, to create one. Go to Azure Portal and launch Cloud Shell from the top navigation.
    Set up job

  2. Follow the instructions to select the environment and subscription to use.
  3. In Cloud Shell, run:
     az ad sp create-for-rbac --name "uuuuuuuu" --password "pppppppp"

    Where uuuuuuuu is the user name and pppppppp is the password for the service principal.

  4. Azure responds with JSON that resembles the following examples:

         "appId": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
         "displayName": "uuuuuuuuuu",
         "name": "http://uuuuuuuu",
         "password": "pppppppp",
         "tenant": "tttttttt-tttt-tttt-tttt-tttttttttttt"

    You will use the values from this JSON response when you add the Azure Service Principal to Jenkins using the Azure Credential plugin. The aaaaaaaa, uuuuuuuu, pppppppp, and tttttttt are placeholder values.

Add Azure service principal to Jenkins

Next, you need to add the Azure service principal to Jenkins credential store using the Azure credential plugin.

  1. From the Jenkins dashboard, select Credentials
  2. Select System and then Add Credentials
  3. In the Add Credentials dialog, select Microsoft Azure Service Principal from the Kind drop-down.
  4. If you don’t know your Azure subscription ID, you can query it from the Cloud Shell:

      az account list

    Enter your subscription ID. Use the appId value for Client ID, password for Client Secret, and tenant for Tenant ID.

    Provide mySP as the ID for this crediatial and enter Azure service principal for description.
    Set up credential

    Verify the service principal authenticates with Azure by clicking Verify Service Principal

I ran into an issue I have an Azure service principal