Azure DevOps GitHub Integration Guide

Author

Reads 887

Blurred Blue Design
Credit: pexels.com, Blurred Blue Design

Integrating Azure DevOps with GitHub is a game-changer for developers, allowing for seamless collaboration and streamlined workflows.

With Azure DevOps, you can connect your GitHub repository to create a single source of truth for your code. This eliminates the need for manual updates and ensures that all team members are working with the latest code.

By integrating Azure DevOps with GitHub, you can automate tasks such as code reviews, testing, and deployment. This saves time and reduces errors, making it easier to deliver high-quality software.

Azure DevOps provides a centralized platform for managing your GitHub repository, including features like branch management and pull request automation.

Prerequisites

To get started with Azure DevOps and GitHub, you'll need to have the following prerequisites in place.

First, you'll need a GitHub account, which you can sign up for at https://github.com. I've found that having a good understanding of GitHub's interface can be really helpful, especially when working with pull requests.

Credit: youtube.com, GitHub Integration with Azure DevOps | Add link to GitHub commit | Update state from GitHub

A crucial next step is to create an Azure account, which can be done at https://azure.com. I've used Azure for various projects and have always been impressed by its scalability and reliability.

You'll also need an Azure DevOps account, which can be created at https://dev.azure.com. This will give you access to a range of tools and features, including pipelines and repositories.

To make the most of Azure DevOps, you'll need to install the ARM Outputs extension in your Azure DevOps account. This can be found at https://marketplace.visualstudio.com/items?itemName=keesschollaart.arm-outputs.

In addition to these accounts, you'll also need to have Git installed on your computer. You can download the latest version from https://git-scm.com/downloads.

Visual Studio Code is another essential tool for this process. You can download it from https://code.visualstudio.com. I've found it to be a really powerful and flexible code editor.

Finally, you'll need to install a couple of extensions in Visual Studio Code. The Azure Pipelines extension can be found at https://marketplace.visualstudio.com/items?itemName=ms-azure-devops.azure-pipelines, while the GitHub Pull Requests extension can be downloaded from https://marketplace.visualstudio.com/items?itemName=GitHub.vscode-pull-request-github.

Here's a summary of the prerequisites:

  • GitHub account from https://github.com
  • Azure account from https://azure.com
  • Azure DevOps account from https://dev.azure.com
  • ARM Outputs extension installed in your Azure DevOps account
  • Git installed from https://git-scm.com/downloads
  • Visual Studio Code installed from https://code.visualstudio.com
  • Azure Pipelines extension for Visual Studio Code installed
  • GitHub Pull Requests extension for Visual Studio Code installed

Setting Up

Credit: youtube.com, Azure DevOps GitHub Integration: How to Set up an Advanced Sync

To set up Azure DevOps with GitHub, you'll need to connect the two services, which can be done via the Azure Pipelines extension in the GitHub Marketplace.

Contoso Air uses GitHub to manage their source code, and they want to host their production site on Azure, so they need to automate the process of moving changes from their source code to production.

The first step is to connect GitHub with Azure DevOps, which will allow them to automate their DevOps scenario and reduce the time-consuming and error-prone manual processes they currently have in place.

You can connect GitHub with Azure DevOps by using the Azure Pipelines extension, which is available in the GitHub Marketplace.

Lab Scenario

In this lab, we'll be illustrating the integration and automation benefits of Azure DevOps by helping a fictitious airline called Contoso Air improve their operations.

Contoso Air has developed their flagship website using Node.js and wants to implement pipelines for continuous integration and continuous delivery to quickly update their public services.

Credit: youtube.com, Using GitHub Actions to Deploy to Azure | DevOps Lab

They want to automate the entire process of deploying and hosting the application in Azure without any manual intervention, freeing up their technology teams to focus on generating business value.

The airline's goal is to spin up all the infrastructure needed to deploy and host the application, and they're looking to Azure DevOps and the cloud to make this happen.

CI/CD Setup

CI/CD Setup is a critical part of any DevOps pipeline. To set up automated CI/CD pipelines with Azure Pipelines, you'll need to connect GitHub with Azure DevOps, which can be done via the Azure Pipelines extension in the GitHub Marketplace.

You'll need to select a project to hold and run the pipelines, and create a CI pipeline by selecting Node.JS as the recommended template if prompted. The YAML file used to define the pipeline must be formatted correctly, with a strict adherence to indentation. You can use tools to format and validate the YAML code.

Credit: youtube.com, How To Deploy Your Application To Azure Using GitHub Actions | CI/CD Pipeline

Here are the basic steps to configure a CI pipeline:

  1. Select the organization and Azure DevOps project that you want to use.
  2. Select the forked repo and create a new pipeline.
  3. Replace the default template with the YAML file that defines the pipeline.
  4. Click Save and run to commit the YAML definition directly to the master branch of the repo.
  5. Follow the build through to completion.

By following these steps, you'll be able to set up a CI pipeline that automates the build and deployment of your code.

Setting Up Automated CI/CD

To set up automated CI/CD, you'll need to connect GitHub with Azure DevOps. This can be done via the Azure Pipelines extension in the GitHub Marketplace.

You'll need to fork a repository on GitHub, clone it locally, and open it in Visual Studio Code. Then, you can copy the clone URL of your forked repository and use it to clone the Git repository in Visual Studio Code.

Once you have your repository set up, you can create a CI pipeline in Azure DevOps. To do this, select the organization and project you want to use, and then select the forked repo. You'll need to create a YAML file to define your pipeline, which will involve selecting a template, such as Node.js, and replacing the default template with the YAML required for your project.

Credit: youtube.com, DevOps CI/CD Explained in 100 Seconds

Here's an example of a YAML file for a Node.js pipeline:

```

pool:

vmImage: 'ubuntu-16.04'

trigger:

- master

steps:

- task: CopyFiles@2

displayName: 'Copy Files to: $(build.artifactstagingdirectory)/Templates'

inputs:

SourceFolder: deployment

Contents: '*.json'

TargetFolder: '$(build.artifactstagingdirectory)/Templates'

- task: Npm@1

displayName: 'npm custom'

inputs:

command: custom

verbose: false

customCommand: 'install --production'

- task: ArchiveFiles@2

displayName: 'Archive $(Build.SourcesDirectory)'

inputs:

rootFolderOrFile: '$(Build.SourcesDirectory)'

includeRootFolder: false

- task: PublishBuildArtifacts@1

displayName: 'Publish Artifact: drop'

```

This YAML file defines a pipeline that triggers on a push to the main branch, installs dependencies, builds the project, and runs tests.

You can also integrate Azure DevOps pipelines with GitHub by following these steps:

1. In your DevOps project, navigate to Pipelines and select Create Pipeline.

2. Next click on GitHub.

3. Next click 'Autorize AzurePipelines' (Requires authentication).

4. Select the GitHub repository where you want to link your Azure Pipelines.

5. Review the selected repository you want to link to and click on 'Approve & Install'.

By following these steps, you can set up automated CI/CD pipelines with Azure Pipelines and GitHub.

Submodules

Submodules can be configured in the Checkout step of your pipeline to download files from submodules. This setting can also be configured from the properties of the Get sources task in your pipeline.

Credit: youtube.com, Gitlab Submodules

To check out your Git submodules, they must be either unauthenticated or authenticated. Unauthenticated submodules are public repos with no credentials required to clone or fetch.

If you have a scenario where a different set of credentials are needed to access the submodules, you can't use the Checkout submodules option. This can happen if your main repository and submodule repositories aren't stored in the same Azure DevOps organization.

In this case, you can use a custom script step to fetch submodules. To do this, you'll need to get a personal access token (PAT) and prefix it with "pat:". Then, base64-encode this prefixed string to create a basic auth token.

Here are the steps to fetch submodules using a custom script step:

  • Get a personal access token (PAT) and prefix it with "pat:".
  • Base64-encode this prefixed string to create a basic auth token.
  • Use a secret variable in your project or build pipeline to store the basic auth token.
  • Use that variable to populate the secret in the Git command.

Storing submodule credentials in a Git credential manager installed on your private build agent isn't effective, as the credential manager may prompt you to re-enter the credentials whenever the submodule is updated.

Pipeline Configuration

Credit: youtube.com, Connect GitHub Repository to Azure DevOps Pipeline | Ep-6

Pipeline Configuration is a crucial step in setting up Azure DevOps and GitHub integration. You can create a CI pipeline in Azure Pipelines by selecting an existing or creating a new Azure DevOps project.

To create a CI pipeline, you'll need to select the organization and project you want to use, which can be done for free if you don't have one already. Select the forked repository and choose Node.JS as the recommended template if prompted.

Here's a step-by-step process to create a CI pipeline:

  1. Select Node.JS as the template.
  2. Replace the default template with the YAML below.
  3. Click Save and run.
  4. Confirm the Save and run to commit the YAML definition directly to the master branch of the repo.
  5. Follow the build through to completion.

Note that YAML is very strict with indentation, so it's recommended to use tools to format and validate the code, especially if you're new to YAML.

Automated Tests

Azure DevOps pipelines can be triggered on a push to the main branch, as seen in the Azure DevOps Pipeline Example for Node.js.

This pipeline installs dependencies, builds the project, and runs tests, making it a comprehensive automated testing setup.

Credit: youtube.com, Running Unit Tests with GitHub Actions (10 of 12) | Automated Software Testing

By integrating automated tests into your pipeline, you can ensure that your code is thoroughly tested and validated before deployment.

The Azure DevOps pipeline example for Node.js demonstrates how to run tests as part of the build process, catching any potential issues early on.

Automated testing helps prevent bugs from making it to production, saving you time and resources in the long run.

In the Azure DevOps pipeline example, dependencies are installed before running tests, ensuring that the necessary packages are available for testing.

This streamlined approach to testing enables you to focus on writing new code, knowing that your existing code is thoroughly tested and validated.

Project Setup

To set up a project in Azure DevOps, you'll need to log into your Azure DevOps organization and select New project.

Next, enter information into the form provided, including a name for your project, an optional description, and choose the visibility. Select 'Git' as the source control type and also select the work item process.

Make sure to choose the right 'visibility' settings for your repository and project, depending on your project and requirements.

Creating a Project

Credit: youtube.com, How to Start a Project - 5 Key Steps

Creating a project is a crucial step in setting up your project. To create an Azure DevOps project, log into your Azure DevOps organisation and select New project.

You'll be presented with a form to fill out. Enter a name for your project, and an optional description if you'd like to add some context. Choose the visibility setting that suits your project's needs, keeping in mind that public repositories are available on GitHub, while private projects are available on Azure DevOps.

Select 'Git' as the source control type and choose the work item process that aligns with your project's requirements.

Use Cases & Recommendations

When choosing between Azure DevOps and GitHub Actions for your project setup, consider the size and complexity of your project. Azure DevOps is an excellent choice for large-scale enterprise environments, especially if you're heavily integrated with Microsoft products like Azure, Visual Studio, and Active Directory.

For smaller projects or open-source contributions, GitHub Actions is a great fit. It offers a simpler, faster solution for CI/CD that's easy to set up and use.

Credit: youtube.com, What is Redis? 6 use cases to boost your projects

If you're working with multiple Azure DevOps organizations and projects, you can create pipelines for your organization's repositories. However, keep in mind that only the first organization's pipelines can be automatically triggered by GitHub commits or pull requests.

Here are some key differences to consider:

In summary, choose Azure DevOps for complex projects and GitHub Actions for smaller, more straightforward projects.

Boards

You can connect Azure DevOps Boards to your GitHub account by navigating to Project Settings and selecting the Boards section, then choosing Connect your GitHub account to use your GitHub account credentials. This will allow you to link GitHub repositories to Azure Boards.

To link repositories, select the repositories you want to link and click Save. You'll then see the new GitHub connection under the project settings, where you can also add or remove additional repositories.

Here are the steps to link GitHub repositories to Azure Boards at a glance:

  • Choose 'Project Settings' and under the Boards section select 'GitHub connections'
  • Choose Connect your GitHub account to use your GitHub account credentials
  • Select the GitHub repositories you want to link to Azure Boards and click 'Save'

Adding a Build Status Badge

Credit: youtube.com, Azure DevOps Build Status Badges

Adding a Build Status Badge is a great way to show off your project's quality. You can do this by clicking the build pipeline to navigate to its overview page.

To integrate the build status badge, you'll need to select Status badge from the ellipses (…) dropdown. This will provide a quick and easy way to integrate the build status wherever you want.

You can use the provided URLs to add the status badge to your own dashboards, or use the Markdown snippet to add it to locations such as Wiki pages. To do this, click the Copy to clipboard button for Sample Markdown.

Once you have the Markdown snippet, you can paste it into your README.md file. To do this, open the README.md file in Visual Studio Code and paste in the clipboard contents at the beginning of the file.

To save the file, press Ctrl+S. You'll also need to commit the changes by entering a commit message like Added build status badge and pressing Ctrl+Enter.

Credit: youtube.com, How to add a GitHub workflow status badge #actions #github #badge

If you're prompted to choose whether you want VS Code to automatically stage all changes and commit them directly, choose Always. If you receive an error prompting you to configure user .name and user.email in git, you can do this by opening a command prompt and entering the following commands: `git config --global user.name "Your Name"` and `git config --global user.email "Your Email Address"`.

Finally, press the Synchronize Changes button at the bottom of the window to push the commit to the server.

Integrating Boards

Integrating Boards is a breeze with Azure DevOps and GitHub. You can connect your GitHub account to Azure DevOps Boards to link your GitHub repositories to your Azure Boards project.

To do this, navigate to your project settings and select the GitHub connections under the Boards section. You can then choose to connect your GitHub account using your account credentials or a Personal Access Token (PAT).

Credit: youtube.com, Integrate Azure Boards and GitHub NOW!

Once connected, you can select the GitHub repositories you want to link to Azure Boards and click Save. After that, you'll see the new GitHub connection under your project settings, where you can also add or remove repositories.

You can also review the Azure Boards application directly from your GitHub account or organization by navigating to Settings -> Integrations -> Applications.

Here are the steps to connect your GitHub account to Azure DevOps Boards:

  1. Choose 'Project Settings' and under the Boards section select 'GitHub connections'.
  2. Choose Connect your GitHub account to use your GitHub account credentials.
  3. Next click 'Authorize AzureBoards'.
  4. Select the GitHub repositories you want to link to Azure Boards and click 'Save'.
  5. Review the selected repositories you want to link to Azure Boards and click on 'Approve, Install, & Authorize'.

By following these steps, you can easily integrate your GitHub repositories with Azure DevOps Boards and start tracking your work with ease.

Branches

You can control which branches get CI triggers with a simple syntax. This syntax allows you to specify the full name of the branch, such as main, or a wildcard, like releases/*.

If you use templates to author YAML files, you can only specify triggers in the main YAML file for the pipeline, not in the template files. This is a limitation to keep in mind when setting up your pipeline.

Diverse team collaborating on a software project in a contemporary office setting.
Credit: pexels.com, Diverse team collaborating on a software project in a contemporary office setting.

You can specify triggers in the main YAML file for the pipeline, and it will be triggered if a change is pushed to main or to any releases branch. However, it won't be triggered if a change is made to a releases branch that starts with old.

If you specify an exclude clause without an include clause, it's equivalent to specifying * in the include clause. This means that all branches will be excluded, except for the ones you've explicitly included.

You can also configure triggers based on tags by using the format #tag. This allows you to trigger builds based on specific tags in your repository.

Batch Changes

Batching your CI/CD process can be a game-changer, especially if you have multiple team members uploading changes frequently.

Batching changes allows you to reduce the number of runs you start, which can save time and resources. This feature is particularly useful when you have many team members uploading changes often.

Credit: youtube.com, Run large-scale changes across your codebase with server-side Batch Changes.

To use batching, you can set the `batch` parameter to `true`. This will cause the system to wait until the current run is completed before starting a new run with all pending changes.

Batching can be tricky to implement, especially in pipelines with multiple stages or approvals. In these cases, it's recommended to split your CI/CD process into two separate pipelines - one for build and one for deployments.

If you're using a multi-stage YAML pipeline, a run must reach a terminal state before the next one can start. This can be a problem if your pipeline goes through approvals and long-running deployment stages.

To avoid this issue, you have a few options:

  • Don't use batching at all
  • Split the pipeline into two separate pipelines - one for CI and one for CD
  • Set conditions on stages to skip them and make a run terminate quickly

Frequently Asked Questions

Is Azure DevOps using GitHub?

Azure DevOps integrates with GitHub.com and GitHub Enterprise Server repositories, allowing for seamless collaboration and project management. Learn more about connecting your Azure DevOps and GitHub accounts.

Is Azure DevOps going to be replaced by GitHub?

Azure DevOps and GitHub are complementary tools, not replacements, as they both utilize Git and offer robust version control capabilities. There's no indication that Azure DevOps will be replaced by GitHub, but rather they'll coexist to serve different needs.

Does Azure DevOps include Git?

Yes, Azure DevOps includes free, unlimited private Git repositories. You'll need the Create repository permission, granted by default to project administrators, to use this feature.

What is the difference between Azure DevOps pipelines and GitHub?

Azure DevOps pipelines (Azure Pipelines) primarily automate Continuous Integration/Continuous Deployment (CI/CD) workflows, while GitHub Actions focuses on automating code review, branch management, and other tasks. Azure Pipelines offers more advanced features like environment management and agent pools, whereas GitHub Actions manages self-hosted runners in groups.

Tiffany Kozey

Junior Writer

Tiffany Kozey is a versatile writer with a passion for exploring the intersection of technology and everyday life. With a keen eye for detail and a knack for simplifying complex concepts, she has established herself as a go-to expert on topics like Microsoft Cloud Syncing. Her articles have been widely read and appreciated for their clarity, insight, and practical advice.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.