Azure and GitHub Integration
Azure and GitHub Integration
Azure and GitHub Integration
GitHub Actions helps you automate your software development workflows from within GitHub. You can deploy
workflows in the same place where you store code and collaborate on pull requests and issues.
In GitHub Actions, a workflow is an automated process that you set up in your GitHub repository. You can build,
test, package, release, or deploy any project on GitHub with a workflow.
Each workflow is made up of individual actions that run after a specific event (like a pull request) occur. The
individual actions are packaged scripts that automate software development tasks.
With GitHub Actions for Azure, you can create workflows that you can set up in your repository to build, test,
package, release, and deploy to Azure. GitHub Actions for Azure supports Azure services, including Azure App
Service, Azure Functions, and Azure Key Vault.
GitHub Actions also include support for utilities, including Azure Resource Manager templates, Azure CLI, and
Azure Policy.
Watch this video from GitHub Universe 2020 to learn more about continuous delivery with GitHub Actions.
Next Steps
Learning path, Automate your workflow with GitHub Actions
Learning Lab, Continuous Delivery with Azure
Use GitHub Actions to connect to Azure
10/22/2021 • 3 minutes to read • Edit Online
Learn how to use Azure login with either Azure PowerShell or Azure CLI to interact with your Azure resources.
To use Azure PowerShell or Azure CLI in a GitHub Actions workflow, you need to first log in with the Azure login
action. The Azure login action allows you to execute commands in a workflow in the context of an Azure AD
service principal.
By default, the action logs in with the Azure CLI and sets up the GitHub action runner environment for Azure CLI.
You can use Azure PowerShell with enable-AzPSSession property of the Azure login action. This sets up the
GitHub action runner environment with the Azure PowerShell module.
You can use Azure login to connect to public or sovereign clouds including Azure Government and Azure Stack
Hub.
appName="myApp"
az ad app create \
--display-name $appName \
--homepage "http://localhost/$appName" \
--identifier-uris http://localhost/$appName
2. Open Azure Cloud Shell in the Azure portal or Azure CLI locally.
NOTE
If you are using Azure Stack Hub, you'll need to set your SQL Management endpoint to not supported .
az cloud update -n {environmentName} --endpoint-sql-management https://notsupported
3. Create a new service principal in the Azure portal for your app. The service principal must be assigned
the Contributor role.
7. Paste in your JSON object for your service principal with the name AZURE_CREDENTIALS .
on: [push]
name: AzureLoginSample
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Log in with Azure
uses: azure/login@v1
with:
creds: '${{ secrets.AZURE_CREDENTIALS }}'
on: [push]
name: AzureLoginSample
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Log in with Azure
uses: azure/login@v1
with:
creds: '${{ secrets.AZURE_CREDENTIALS }}'
enable-AzPSSession: true
- name: Azure PowerShell Action
uses: Azure/powershell@v1
with:
inlineScript: Get-AzVM -ResourceGroupName "< YOUR RESOURCE GROUP >"
azPSVersion: 3.1.0
name: AzureLoginSample
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
The following articles provide support to deploy apps from GitHub to Azure.
Azure Functions
Deploy a function app continuously from GitHub
Deploy to Azure Functions using GitHub Actions
Azure Storage
Set up a GitHub Actions workflow to deploy your static website in Azure Storage
Azure Pipelines
Trigger a Pipeline run from GitHub Actions
Azure Resource Manager templates
Deploy Bicep files by using GitHub Actions
Deploy Azure Resource Manager templates by using GitHub Actions
Azure Stack
Use the Azure login action with Azure CLI and PowerShell on Azure Stack Hub
Deploy databases from GitHub to Azure
10/22/2021 • 2 minutes to read • Edit Online
The following articles provide support to deploy database updates from GitHub to Azure. You can use GitHub
Actions to deploy to Azure SQL, Azure MySQL, and Azure Database for PostgreSQL.
Use GitHub Actions to connect to Azure SQL Database
Use GitHub Actions to connect to Azure MySQL
Use GitHub Actions to connect to Azure PostgreSQL
Use variable substitution with GitHub Actions
10/22/2021 • 2 minutes to read • Edit Online
Learn how to use variable substitution action to replace values in XML, JSON and YAML based configuration and
parameter files.
Variable substitution lets you insert values, including GitHub secrets, into files in your repository during the
workflow run. For example, you could insert an API login and password into a JSON file during the workflow
run.
Variable substitution only works for keys predefined in the object hierarchy. You cannot create new keys with
variable substitution. In addition, only variables defined as environment variables in the workflow or system
variables that are already available can be used for substitution.
Prerequisites
A GitHub account. If you don't have one, sign up for free.
{
"first-name": "Toni",
"last-name": "Cranz",
"username": "",
"password": "",
"url": ""
}
on: [push]
name: variable substitution in json
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: microsoft/variable-substitution@v1
with:
files: 'employee.json'
env:
username: tcranz
password: ${{ secrets.PASSWORD }}
url: https://github.com/${{github.repository}}
7. Go to Actions to see your workflow run. Open the variable substitution action. You should see that each
variable was replaced.
Clean up resources
Delete your GitHub repository when it is no longer needed.
Next steps
Deploy to Azure Web Apps using GitHub Actions
Use Key Vault secrets in GitHub Actions workflows
10/22/2021 • 3 minutes to read • Edit Online
Use Key Vault secrets in your GitHub Actions and securely store passwords and other secrets in an Azure key
vault. Learn more about Key Vault.
With Key Vault and GitHub Actions, you have the benefits of a centralized secrets management tool and all the
advantages of GitHub Actions. GitHub Actions is a suite of features in GitHub to automate your software
development workflows. You can deploy workflows in the same place where you store code and collaborate on
pull requests and issues.
Prerequisites
A GitHub account. If you don't have one, sign up for free.
An Azure account with an active subscription. Create an account for free.
An Azure App connected to a GitHub repository. This example uses Deploy containers to Azure App Service.
An Azure key vault. You can create an Azure Key Vault using the Azure portal, Azure CLI, or Azure PowerShell.
SEC T IO N TA SK S
Authentication
You can create a service principal with the az ad sp create-for-rbac command in the Azure CLI. Run this
command with Azure Cloud Shell in the Azure portal or by selecting the Tr y it button.
In the example above, replace the placeholders with your subscription ID and resource group name. Replace the
placeholder myApp with the name of your application. The output is a JSON object with the role assignment
credentials that provide access to your App Service app similar to below. Copy this JSON object for later. You will
only need the sections with the clientId , clientSecret , subscriptionId , and tenantId values.
{
"clientId": "<GUID>",
"clientSecret": "<GUID>",
"subscriptionId": "<GUID>",
"tenantId": "<GUID>",
(...)
}
- uses: Azure/get-keyvault-secrets@v1
with:
keyvault: "my Vault" # name of key vault in Azure portal
secrets: 'mySecret' # comma separated list of secret keys to fetch from key vault
id: myGetSecretAction # ID for secrets that you will reference
To use a key vault in your workflow, you need both the key vault action and to reference that action.
In this example, the key vault is named containervault . Two key vault secrets are added to the environment
with the key vault action - containerPassword and containerUsername .
The key vault values are later referenced in the docker login task with the prefix
steps.myGetSecretAction.outputs .
name: Example key vault flow
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
# checkout the repo
- uses: actions/checkout@v2
- uses: Azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- uses: Azure/get-keyvault-secrets@v1
with:
keyvault: "containervault"
secrets: 'containerPassword, containerUsername'
id: myGetSecretAction
- uses: azure/docker-login@v1
with:
login-server: myregistry.azurecr.io
username: ${{ steps.myGetSecretAction.outputs.containerUsername }}
password: ${{ steps.myGetSecretAction.outputs.containerPassword }}
- run: |
docker build . -t myregistry.azurecr.io/myapp:${{ github.sha }}
docker push myregistry.azurecr.io/myapp:${{ github.sha }}
- uses: azure/webapps-deploy@v2
with:
app-name: 'myapp'
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
images: 'myregistry.azurecr.io/myapp:${{ github.sha }}'
Clean up resources
When your Azure app, GitHub repository, and key vault are no longer needed, clean up the resources you
deployed by deleting the resource group for the app, GitHub repository, and key vault.
Next steps
Learn more about Azure Key Vault
Manage Azure Policies with GitHub
10/22/2021 • 2 minutes to read • Edit Online
Review the following articles to learn how to manage Azure Policies as code from GitHub
Export Azure Policies from Azure
Manage Azure Policies as code from GitHub
Trigger Azure compliance scans
Build custom virtual machine images with GitHub
Actions and Azure
10/22/2021 • 6 minutes to read • Edit Online
Get started with the GitHub Actions by creating a workflow to build a virtual machine image.
With GitHub Actions, you can speed up your CI/CD process by creating custom virtual machine images with
artifacts from your workflows. You can both build images and distribute them to a Shared Image Gallery.
You can then use these images to create virtual machines and virtual machine scale sets.
The build virtual machine image action uses the Azure Image Builder service.
Prerequisites
An Azure account with an active subscription. Create an account for free.
A GitHub account with an active repository. If you don't have one, sign up for free.
This example uses the Java Spring PetClinic Sample Application.
A Shared Image Gallery.
Create a Shared Image Gallery with the Azure CLI
Create an Azure Shared Image Gallery using the portal (Windows, Linux)
SEC T IO N TA SK S
3. Use this JSON code to create a new custom role with JSON.
appName="myApp"
az ad app create \
--display-name $appName \
--homepage "http://localhost/$appName" \
--identifier-uris http://localhost/$appName
2. Create a new service principal in the Azure portal for your app.
6. Paste in your JSON object for your service principal with the name AZURE_CREDENTIALS .
jobs:
build-image:
runs-on: ubuntu-latest
steps:
- name: Log in with Azure
uses: azure/login@v1
with:
creds: '${{ secrets.AZURE_CREDENTIALS }}'
Configure Java
Set up the Java environment with the Java Setup SDK action. For this example, you'll set up the environment,
build with Maven, and then output an artifact.
GitHub artifacts are a way to share files in a workflow between jobs. You'll create an artifact to hold the JAR file
and then add it to the virtual machine image.
on: [push]
jobs:
build-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: CREATE VM
uses: azure/CLI@v1
with:
azcliversion: 2.0.72
inlineScript: |
az vm create --resource-group ghactions-vMimage --name "app-vm-${{ GITHUB.RUN_NUMBER }}" --admin-
username myuser --admin-password "${{ secrets.VM_PWD }}" --location eastus2 \
--image "${{ steps.imageBuilder.outputs.custom-image-uri }}"
Complete YAML
on: [push]
jobs:
build-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: CREATE VM
uses: azure/CLI@v1
with:
azcliversion: 2.0.72
inlineScript: |
az vm create --resource-group ghactions-vMimage --name "app-vm-${{ GITHUB.RUN_NUMBER }}" --
admin-username myuser --admin-password "${{ secrets.VM_PWD }}" --location eastus2 \
--image "${{ steps.imageBuilder.outputs.custom-image-uri }}"
Next steps
Learn how to deploy to Azure.
Work with Azure DevOps and GitHub
10/22/2021 • 2 minutes to read • Edit Online
Review the following article to learn how Azure DevOps works with GitHub.
Connect Azure Boards with GitHub
Link Azure Boards work items to GitHub commits, pull requests and issues
Use Azure Pipelines to build GitHub repositories
Create a GitHub Release from Azure Pipelines
Use Visual Studio or Visual Studio Code to deploy
apps from GitHub
10/22/2021 • 2 minutes to read • Edit Online
Review the following article to learn how to use Visual Studio or Visual Studio Code with GitHub.
Deploy to Azure App Service using Visual Studio Code
Visual Studio subscription with GitHub offer
And, the following Marketplace extensions provide developer support for integrating with GitHub.
GitHub extension for Visual Studio
GitHub extension for Visual Studio Code
You can also use Visual Studio and Visual Studio Code to create your own actions.
Tutorial: Create a GitHub Action with .NET