Azure Pipeline Part 5 – Checkout

Azure Pipeline Part 5 – Checkout

Azure Pipeline Part 5 – Checkout

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

Today we are going to discuss how to clone multiple git repositories in Azure Pipelines using checkout block. By default, the repository hosting your azure pipeline config YAML file gets cloned when you execute a pipeline. But your pipeline may require source code hosted in different git repositories. In such scenarios, you can use checkout block inside a job to clone other git repositories.

Note: In order to use checkout block in your Azure pipeline, you first need to define repository resource in the pipeline config YAML file.

Next, we are going to clone a GitHub repository in our Azure Pipeline using checkout block.

Azure Pipeline Part 5 – Checkout

Prerequisites:

Setup:

Azure Pipeline – Checkout:

By using multiple checkout steps in your pipeline, you can fetch and check out other repositories in addition to the one you use to store your YAML pipeline.

Azure Pipeline – Checkout syntax:

Azure Pipeline – Repository Resource syntax:

Since we are using a GitHub repository, we can use service connection feature to define the GitHub endpoint in Azure DevOps project.

Create a service connection for GitHub:

Step 1: Log in to Azure DevOps portal and navigate to the project where your pipeline is hosted.

Step 2: Navigate to your Azure DevOps project setting page => Pipelines => Service connections and click “Create service connection”.

Azure Pipeline Part 5 – Checkout

Step 3: Select “GitHub” and click “Next”.

Azure Pipeline Part 5 – Checkout

Step 4: Provide personal access token of your GitHub account, service connection name and click “Verify and save”.

Azure Pipeline Part 5 – Checkout

Note: The service connection name (in our case “MyGitHub”) will be used in the repository resource endpoint to refer this GitHub connection.

Now we are ready to create pipeline config YAML file and clone the GitHub repository using this service connection.

Step 5: Create the pipeline config YAML file and push the changes to Azure repos.

You might need to provide the access to your pipeline to use the GitHub service endpoint.

Azure Pipeline Part 5 – Checkout

Azure Pipeline Part 5 – Checkout

Observe, we have both the repository checked out in our pipeline.

Azure Pipeline Part 5 – Checkout

Clean up:

Hope you have enjoyed this article. To know more about Azure DevOps, please refer below official documentation

https://docs.microsoft.com/en-us/azure/devops/?view=azure-devops

Leave a Reply

Close Menu