Credits and sources
Microsoft Learn
https://learn.microsoft.com/en-us/azure/devops/cross-service/github-integration?view=azure-devops https://learn.microsoft.com/en-us/azure/devops/boards/github/?view=azure-devops https://docs.github.com/en/issues/planning-and-tracking-with-projects/learning-about-projects/about-projectsIntro
In this blog post, I will show how to use Azure DevOps pipelines with source code placed in GitHub. I will also show you how to integrate GitHub with Azure DevOps boards so that you can manage your project in Azure DevOps and close work items by using commits to your GitHub repository.
This can be useful in migration scenarios and scenarios where you want the repository features from GitHub together with Azure DevOps features like project management and pipelines.
For the demo purpose, I will create an Azure App Service running a Python Flask website inside a container.
GitHub repository
First, I will create a new repository in GitHub. I will name it “azure-devops-with-github” and make it private.
I will upload some code to this repository later.
Azure DevOps project and service connection
Next, I will create a new project in Azure DevOps. I do this from the main page, using the “New project” button at the top right corner.
I will call my project “Azure DevOps with GitHub repositories.” I will keep the default settings and create a private project.
The first thing I want to do in the new project is to connect it with the GitHub repository I created in the first step. I created the connection by going to the “Project settings.”
Then go to the “GitHub Connections.”
I will choose my private GitHub account.
Next, I will search for my new repository, mark it, and click “Save.”
I will make sure I have “Only select repositories” marked and that only my new repository is added. Then, click on “Approve, Install & Authorize.”
After that, I can see my connection in Azure DevOps.
Create work items in Azure DevOps
To test the boards’ integration with GitHub, I have created a small number of work items. These work items are created in an agile project using Epics, Features, User Stories, and Tasks. In the next section, I will show how I can update these tasks using commits in GitHub.
Commit changes to GitHub repository to interact with Azure DevOps work items
One of the good things about connecting GitHub and Azure DevOps is that it is possible to update the work items by making commits to the connected repository. The process is very simple: Just a few keywords followed by the work item ID, and the updating can happen. Below, I have marked the work items I want to complete with a new commit to the repository.
To close these work items, I must make a new commit to the repository and include the following text in the commit message.
Fixes AB#115, fixes AB#116, fixes AB#117
I can add more text to the commit message, but the above is a requirement. It is a bit annoying that I can’t just type “Fixes AB#115,AB#116,AB#117,” and it would also be nice to be able to do other status updates besides closing.
If I look at my work items overview now, the work items I just closed are gone.
I can verify that the commit was the reason the items were closed by finding the closed user story. On the right side is the GitHub commit and also the status of the two child tasks.
Azure infrastructure code
For this blog post, I created some demo resources that I can use to show the functionality. They are a resource group, container registry, app service plan, and app service. The code is below, but use it at your own risk and ensure that all security settings for your environment are applied if you copy it.
resource "azurerm_resource_group" "main" {
name = "rg-azure-devops-github-repo"
location = "westeurope"
}
resource "azurerm_service_plan" "main" {
name = "asp-azure-devops-github"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
os_type = "Linux"
sku_name = "B1"
}
resource "azurerm_linux_web_app" "main" {
name = "app-azure-devops-github"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_service_plan.main.location
service_plan_id = azurerm_service_plan.main.id
client_certificate_mode = "Required"
https_only = true
app_settings = {
minTlsVersion = "1.2"
ENABLE_ORYX_BUILD = true
DISABLE_COLLECTSTATIC = true
SCM_DO_BUILD_DURING_DEPLOYMENT = true
}
identity {
type = "SystemAssigned"
}
site_config {
ftps_state = "FtpsOnly"
container_registry_use_managed_identity = true
application_stack {
docker_image_name = "demo"
docker_registry_url = azurerm_container_registry.main.login_server
}
}
lifecycle {
ignore_changes = [
site_config,
]
}
}
resource "azurerm_container_registry" "main" {
name = "demoregistryinazure"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
sku = "Basic"
admin_enabled = false
}
resource "azurerm_role_assignment" "acr_pull" {
scope = azurerm_container_registry.main.id
role_definition_name = "AcrPull"
principal_id = azurerm_linux_web_app.main.identity[0].principal_id
}
Website
I created a small website using Python Flask; I won’t put the code here, but it is a simple site that says, “Welcome to the cloudninja demo website.”
Azure DevOps pipeline for infrastructure
Now, I need to create the pipeline for the deployments. First, I need to go to “Pipelines” and click on “New pipeline.”
Select “GitHub.”
Click “Authorize AzurePipelines.”
I search for the repository and click it.
Click “Approve & install.”
Sign in with your account for Azure DevOps.
Select “Starter pipeline.”
I will delete the contents and add the code, as shown below. Click “Save and run.”
I will commit this to the main branch.
Below is the result of the pipeline run.
Azure DevOps pipeline for website
I could create another pipeline for the website deployment, but instead, I will add the website deployment to the existing pipeline I use for infrastructure deployments.
First, I will add some variables to the pipeline.
Then, I will add a task to build my container, upload it to the container registry, and deploy it to my app service.
Below is the result of the pipeline run.
I can verify that my deployment was successful by opening the website where I just deployed.
Summary
In this blog post, I have shown how to integrate Azure DevOps and GitHub. The integration is straightforward to configure, and after a few commits, the integration with work items also feels very native. The main reason for me to do this integration is that Azure DevOps has a project management flow that integrates with coding. This feature is not in GitHub, at least not on the same level as Azure DevOps does. This configuration also has caveats since you must buy licenses for Azure DevOps and GitHub unless you are OK with the free versions. GitHub Projects might be enough if you only do simple task management.