GitHub Actions for Azure
Integrate your Azure workflows seamlessly with GitHub Actions. Automate deployments, build processes, and manage your Azure resources directly from your GitHub repositories.
Key Concepts
GitHub Actions is a CI/CD platform that allows you to automate software development workflows. When combined with Azure, you can achieve powerful end-to-end automation.
Workflows
Workflows are automated processes that can be run when specific events occur in your GitHub repository (e.g., push, pull request, scheduled events). They are defined in YAML files stored in the .github/workflows directory of your repository.
Events
Events trigger workflows. Common Azure-related events include:
push: When code is pushed to a repository.pull_request: When a pull request is opened, synchronized, or closed.schedule: Run workflows at specified times.
Jobs
A job is a set of steps that are executed on a runner. Jobs in a workflow can run in parallel or sequentially.
Steps
Steps are individual tasks within a job. They can be commands, scripts, or predefined actions.
Actions
Actions are reusable units of code that can perform complex tasks. Microsoft provides a rich set of official Azure Actions for common scenarios.
Common Azure Actions
Authenticating with Azure
Before performing any Azure operations, you need to authenticate. The recommended way is to use the azure/login action.
- name: Log in to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
The secrets.AZURE_CREDENTIALS secret should contain your Azure service principal credentials in JSON format.
Deploying to Azure App Service
Automate the deployment of your web applications to Azure App Service.
- name: Deploy to Azure App Service
uses: azure/webapps-deploy@v2
with:
app-name: my-azure-app
package: ./app.zip
Deploying to Azure Kubernetes Service (AKS)
Deploy your containerized applications to AKS.
- name: Deploy to AKS
uses: azure/aks-deploy@v1
with:
cluster-name: my-aks-cluster
resource-group: my-resource-group
kubeconfig: ${{ secrets.KUBECONFIG }}
manifests: |
manifests/deployment.yaml
manifests/service.yaml
Running Azure CLI Commands
Execute any Azure CLI command within your workflow.
- name: Run Azure CLI command
run: az group create --name my-resource-group --location eastus
Getting Started
- Create a Service Principal: In your Azure subscription, create a service principal with the necessary permissions for your GitHub Actions workflows.
- Store Credentials as a Secret: In your GitHub repository's settings, go to "Secrets and variables" > "Actions" and add a new repository secret named
AZURE_CREDENTIALS. Paste the JSON output of your service principal credentials into this secret. - Create a Workflow File: In your repository, create a directory named
.github/workflowsand add a YAML file (e.g.,azure_deploy.yml). - Define Your Workflow: Add the necessary steps to your YAML file, including authentication and the specific Azure actions you want to use.