Exercise - Configure continuous integration by using Azure Pipelines

Completed

In this exercise, you deploy a container app from an image in the Azure Container Registry to the Azure Container Apps platform.

The following Azure resources must be available in your Resource group named RG1:

  • A Container registry instance that contains one image.
  • A Virtual network with subnets.
  • A Service Bus Namespace
  • A Managed Identity
  • A Private endpoint
  • A Container App
  • A Container Apps Environment

You've been asked to configure a continuous integration environment for Container Apps that meets the following requirements:

  • You need an Azure Container Apps deployment task in your Azure DevOps environment.
  • Pipeline1 must deploy a container image from your container registry to your container app using a self-hosted agent pool.
  • You must ensure that the pipeline successfully deploys the image at least once.

You complete the following tasks during this exercise:

  1. Configure Pipeline1 to use the self-hosted agent pool.

  2. Configure Pipeline1 with an Azure Container Apps deployment task.

  3. Run the Pipeline1 deployment task.

  4. Verify the configuration.

Configure Pipeline1 to use the self-hosted agent pool

  1. Open a browser window, navigate to https://dev.azure.com, and then open your Azure DevOps organization.

  2. On your Azure DevOps page, to open your DevOps project, select Project1.

  3. In the left-side menu, select Pipelines.

  4. Select Pipeline1, and then select Edit.

  5. To use the self-hosted agent pool, update the azure-pipelines.yml file as shown in the following example:

    trigger:
    - main
    
    pool:
      name: default
    
    steps:
    

    Recall that the pool section specifies the agent pool to use for the pipeline. The name property specifies the name of the agent pool. In this case, the name is default, which is the pool you configured as a self-hosted agent pool.

  6. Under Validate and save, select Save without validating.

  7. Enter a commit message, and then select Save.

Configure Pipeline1 with an Azure Container Apps deployment task

  1. Ensure that you have Pipeline1 open for editing.

  2. On the right side under Tasks, in the Search tasks field, enter azure container

  3. In the filtered list of tasks, select Azure Container Apps Deploy

  4. Under Azure Resource Manager connection, select the Subscription you're using, and then select Authorize.

  5. In the Azure portal tab, open your Container App resource, and then open the Containers page.

  6. Use the information on the Containers page to configure the following Pipeline1 Task information:

    • Docker Image to Deploy: <Registry>/<Image>:<Image tag>
    • Azure Container App name: <Name>
  7. Configure the following Pipeline1 Task information:

    • Azure Resource group name: RG1

    Note

    If you need to verify the resource group name, you can find it on the Overview page of your Container App resource.

  8. On the Azure Container Apps Deploy page, select Add.

    The Yaml file for your pipeline should now include the AzureContainerApps tasks as follows:

    trigger:
      - main
    pool:
      name: default
    steps:
      - task: AzureContainerApps@1
        inputs:
          azureSubscription: '<Subscription>(<Subscription ID>)'
          imageToDeploy: '<Registry>/<Image>:<Image tag>' from Container App resource
          containerAppName: '<Name>' from Container App resource 
          resourceGroup: '<resource group name>'
    
    

    Here's an example that shows a YAML configuration snippet:

    trigger:
      - main
    pool:
      name: default
    steps:
      - task: AzureContainerApps@1
        inputs:
          azureSubscription: 'Visual Studio Enterprise(1111aaaa-22bb-33cc-44dd-555555eeeeee)'
          imageToDeploy: 'acraz2003cah12oct.azurecr.io/aspnetcorecontainer:latest'
          containerAppName: 'aca-az2003'
          resourceGroup: 'RG1'
    
  9. Select Validate and save, and then select Save again to commit directly to the main branch.

    The contents of the YAML file must be formatted correctly, including indentation. If you encounter an error, review the YAML file and correct any indentation issues.

  10. Navigate back to the main page of your pipeline.

Run the Pipeline1 deployment task

  1. Ensure that you have Pipeline1 open in Azure DevOps.

  2. On the Runs tab of the Pipeline1 page, select Run pipeline.

    A Run pipeline page opens to display the associated job.

  3. Select Run.

    The Jobs section displays job status, which progresses from Queued to Waiting.

    It can take a couple minutes for the status to transition from Queued to Waiting.

  4. If a 'Permission needed' message is displayed ("This pipeline needs permission to access 2 resources before this run can continue"), select View and then provide the required permissions.

  5. Monitor the status of the run operation and verify that the run is successful.

    Screenshot of Azure Pipelines showing a successful run of Pipeline1.

Check your work

In this task, you examine your pipeline and container app to verify successful pipeline runs.

  1. Ensure that you have Project1 open in Azure DevOps.

  2. On the left side menu, select Pipelines, and then select Pipeline1.

  3. The Runs tab displays individual runs that can be selected to review details.

    Screenshot of Azure Pipelines showing the Runs tab for Pipeline1 after running the job.

  4. Open your Azure portal, and then open your Container App.

  5. On the left side menu, select Activity Log.

  6. Verify that a Create or Update Container App operation succeeded as a result of running your pipeline.

    Screenshot of a Container App Activity Log showing a successful Create or Update Container App operation.

    Notice that the Event initiated by column on the right shows your Project1 as the source.