Linking Azure DevOps to GitHub can greatly enhance your development workflow. This integration allows you to manage your code repositories and work items in one place.
By linking your Azure DevOps and GitHub accounts, you can easily clone repositories, create new work items, and link them to specific commits. This streamlines your workflow and eliminates the need to constantly switch between different tools.
Having a unified view of your code and work items helps you stay organized and focused on your projects. You can also use Azure DevOps to manage pull requests and code reviews, making it easier to collaborate with team members.
With the integration, you can also automate tasks and workflows using Azure DevOps Pipelines, making your development process even more efficient.
Prerequisites
To link Azure DevOps to GitHub, you'll first need to ensure a few prerequisites are met.
Your Azure Boards project must be connected to the GitHub repository where the commits, pull requests, and branch you want to link to/from exist. For more information, see Azure Boards-GitHub integration.
You must be a Contributor to both the Azure Boards project and the GitHub repository.
For projects that use the Hosted XML process model, you'll need to update the work item types to view the Development section and GitHub link types. See Update XML definitions for select work item types for more information.
If you don't have an Azure Boards or Azure DevOps project yet, create one.
You can connect to an existing project or create a new one to link to GitHub.
Linking Azure DevOps to GitHub
Linking Azure DevOps to GitHub allows you to easily reference and transition work items between the two platforms. You can use the AB# syntax to create a link to your Azure Boards work item from a GitHub commit, pull request, or issue.
To create a link, enter the AB#ID within the text of a commit message, or within the title or description of a pull request or issue. For example, AB#125 links to work item ID 125.
You can also use the AB# syntax to transition a work item. The system recognizes fix, fixes, and fixed, and applies it to the #-mention item that follows. For instance, if your commit message is "Fixed AB#123", the work item will be linked and transitioned to the Resolved workflow state category or, if none is defined, then the Completed workflow state category.
Here are some examples of how you can use the AB# syntax in a commit or pull request message:
Keep in mind that linking to GitHub issues requires Azure DevOps Server 2019 Update 1 or later version.
Creating a Connection
Creating a connection between Azure DevOps and GitHub is a straightforward process. You can connect up to 500 GitHub repositories to an Azure Boards project.
To start, you'll need to create a repository on GitHub, which will serve as the central hub for your source code. The URL of this repository will be used to connect your local Git repository to the hosted one.
Once you have your repository set up, you can add a GitHub connection to your Azure Boards project. This involves signing in with your GitHub credentials and selecting the GitHub account or organization you want to connect.
You can use either OAuth or a Personal Access Token (PAT) to connect to GitHub. If you're using OAuth, you'll need to enter your GitHub credentials and select Verify if you have two-factor authentication enabled. If you're using a PAT, you'll need to create one with the required scopes: repo, read:user, user:email, and admin:repo_hook.
If you're connecting to a GitHub Enterprise Server, you'll need to ensure that your server is accessible from the Internet and that Azure DNS can resolve your server's name. You'll also need to allow access from Azure Data Center IP addresses.
In terms of limits, you can connect up to 500 GitHub repositories to an Azure Boards project. However, if you're connecting to a GitHub Enterprise Server, you're limited to connecting up to 250 repositories (or 100 repositories if you're using Azure DevOps Server 2019).
Here are the steps to connect Azure DevOps to GitHub:
- Create a repository on GitHub
- Add a GitHub connection to your Azure Boards project
- Choose your authentication method (OAuth or PAT)
- Enter your GitHub credentials or PAT
- Select the repositories you want to connect to your project
By following these steps, you can establish a seamless connection between Azure DevOps and GitHub, enabling you to link commits and pull requests to work items and streamline your software development process.
Resolve Access Issues
If you're experiencing issues connecting Azure DevOps to GitHub, changes to your permission scope or authentication credentials can revoke the GitHub repositories connected to Azure Boards.
The Azure Boards-GitHub integration relies on various authentication protocols to support the connection.
To resolve access issues, consider the following steps:
- Remove and re-create the connection to the GitHub Enterprise Server repository. Follow the sequence of steps provided in Connect from Azure Boards documentation.
- Fix the webhook URL by editing the GitHub repository settings page and pointing it to the migrated Azure DevOps organization URL: https://dev.azure.com/{OrganizationName}/_apis/work/events?api-version=5.2-preview
Changes to your authentication credentials can cause revocation of the GitHub repositories connected to Azure Boards.
Configuring Integration
To configure integration between Azure DevOps and GitHub, you'll need to register your OAuth configuration in Azure DevOps Services. This involves signing into the web portal, adding the GitHub Enterprise OAuth configuration to your organization, and entering your information to create the configuration.
You can then integrate Azure DevOps Boards with GitHub by choosing 'Project Settings' and selecting 'GitHub connections' under the Boards section. From there, you can connect your GitHub account using your credentials or a Personal Access Token (PAT).
Here are the steps to integrate Azure DevOps Boards with GitHub:
- Choose 'Project Settings' and under the Boards section select 'GitHub connections'.
- Choose Connect your GitHub account to use your GitHub account credentials.
- Next click 'Authorize AzureBoards'.
- Select the GitHub repositories you want to link to Azure Boards and click 'Save'.
- Review the selected repositories you want to link to Azure Boards and click on 'Approve, Install, & Authorize'.
By following these steps, you can establish a seamless integration between Azure DevOps and GitHub, allowing you to link work items to GitHub branches, commits, or pull requests.
Update XML Definitions for Select Work Item Types
To update XML definitions for select work item types, you need to customize the work tracking experience and link to and view GitHub link types from the Development section in the work item forms.
If your organization uses the Hosted XML or on-premises XML process model, you'll need to update the XML definitions for the work item types that you want to integrate with GitHub.
To modify the XML definitions, follow the sequence of tasks provided in the Hosted XML process model. For each work item type, locate the Group Label="Development" section.
In this section, add the following two lines of code to support the external link types: GitHub Commit and GitHub Pull Request.
For example, to link user stories and bugs to GitHub commits and pull requests, update the XML definitions for user stories and bugs.
After updating the XML definitions, the section should appear with the added lines of code.
Here's a summary of the steps:
- Locate the Group Label="Development" section.
- Add the following lines of code to support the external link types: GitHub Commit and GitHub Pull Request.
Link to Boards Work Items
You can link to Azure Boards work items from GitHub using the AB# syntax. This syntax creates a link to the work item and allows you to transition the work item to the Resolved workflow state category or, if none is defined, then the Completed workflow state category.
To use the AB# syntax, simply enter the AB#ID within the text of a commit message, or for a pull request or issue, enter the AB#ID within the title or description. For example, AB#125 links to work item ID 125.
You can also use the AB# syntax to transition work items by mentioning "fix", "fixes", or "fixed" followed by the AB#ID. For example, "Fixed AB#123" links and transitions the work item to the Resolved workflow state category or, if none is defined, then the Completed workflow state category.
Here are some examples of how to use the AB# syntax:
Note that if you connect the same GitHub repo to projects defined in two or more Azure DevOps organizations, you might see unexpected AB# mention linking. For this reason, it's recommended to only connect a GitHub repo to projects defined in a single Azure DevOps organization.
Managing Repositories
You can create a repository to host your source code and allow your teams to interact, change, and approve. This is the first step in linking Azure DevOps to GitHub.
To create a repository, set up your repository so you can use the URL of the repo to connect your local Git repository with the hosted one. The scripts use the name of the remote URL on GitHub as https://github.com/user/repo.git.
You can connect up to 500 GitHub repositories to an Azure Boards project. This means you can manage multiple repositories from a single Azure DevOps project.
To connect a GitHub repository, sign in to your project and select Project settings > GitHub connections. If this is your first time connecting from the project, select Connect your GitHub account to use your GitHub account credentials.
You can use one of three authentication methods to connect: OAuth, PAT, or Username plus password. If you choose OAuth, you'll need to use your GitHub account credentials to authenticate.
If you need to use a PAT, make sure to include the following scopes: repo, read:user, user:email, admin:repo_hook. This will ensure that your PAT has the necessary permissions to connect to your GitHub repository.
Here are the authentication methods you can use to connect a GitHub repository:
- OAuth
- PAT
- Username plus password
Remember to choose the right authentication method for your needs, and make sure to include the necessary scopes if you're using a PAT.
Authentication Options
To link Azure DevOps to GitHub, you'll need to understand the authentication options available for each platform. GitHub.com supports GitHub.com user account and Personal access token (PAT) authentication options, while GitHub Enterprise Server supports OAuth (preferred, registration required), PAT, and Username plus password.
You can choose to connect GitHub with a PAT, but you'll need to configure single sign-on (SSO) for the PAT on your GitHub account. This configuration is necessary to retrieve a list of repositories from an organization with Security Assertion Markup Language (SAML) SSO authentication enabled.
To use OAuth with Azure DevOps, you'll need to register the application as an OAuth App. This can be done by following the steps outlined in the Azure DevOps documentation.
To register your OAuth configuration in Azure DevOps Services, follow these steps:
- Sign into the web portal for Azure DevOps Services.
- Add the GitHub Enterprise Oauth configuration to your organization.
- In Organization settings, select Oauth configurations > Add Oauth configuration.
- Enter your information, and then select Create.
Keep in mind that the authentication options available will depend on the GitHub platform you're connecting to.
Next Steps
Now that you've linked Azure DevOps to GitHub, here are the next steps to take your workflow to the next level.
First, you'll want to link GitHub commits and pull requests to work items. This will allow you to track changes and updates in your code directly in Azure DevOps.
To do this, you'll need to follow the steps outlined in the Azure DevOps documentation. This will ensure a seamless integration between your GitHub repository and Azure DevOps project.
By linking GitHub commits and pull requests to work items, you'll be able to see a clear history of changes and updates in your code. This will help you identify potential issues and improve your overall development process.
Sources
- https://azuredays.com/2020/07/14/set-up-git-set-up-with-repository-on-github-or-azure-devops-repos/
- https://learn.microsoft.com/en-us/azure/devops/boards/github/connect-to-github
- https://learn.microsoft.com/en-us/azure/devops/boards/github/link-to-from-github
- https://dev.to/pwd9000/integrating-azure-devops-with-github-hybrid-model-3pkg
- https://github.com/MicrosoftDocs/azure-devops-docs/blob/main/docs/boards/github/connect-on-premises-to-github.md
Featured Images: pexels.com