Now Up To  80% OFF  GitKraken Pro
Upgrade to Save
Search
Close this search box.

Git Blog

Releasing the Power of Git

GitHub Actions for Azure

This post was written by guest author, Nahla Davies. Nahla has been in the software space since 2010 and a technical writer since 2019. She previously served as a lead programmer at an Inc. 5,000 experiential branding organization whose clients include Samsung, Time Warner, Netflix, and Sony.

Microsoft Azure is widely popular among developers and across organizations because it’s scalable, flexible, and customizable. Rather than work against it, Microsoft has embraced the open-source movement by offering a new way to automate development and deployment with GitHub Actions for Azure. 

GitHub Actions is a tool that allows teams to automate software development workflows that work together with Azure Pipelines and your customized needs. Developers can create workflows in their repositories to build, test, package, release, and deploy any project from GitHub to Azure without manual input. This process helps make development and delivery smarter and more efficient so that your teams can focus on developing great code instead of handling repetitive manual tasks. 

What else can you do with GitHub Actions? How does it work exactly? This guide will answer these questions and more. 

Core Elements of a GitHub Action

Before you get started with GitHub Actions for Azure, especially if you are new to backend workflow automation, you should get acquainted with the following GitHub Actions syntax.

  • Workflows
  • Events
  • Jobs
  • Actions
  • Runners

Let’s dive a little deeper into what each of these elements means.

Workflows

A workflow is a custom automated process that runs one or more jobs to simplify testing, development, and delivery. They are defined by YAML files in your repository that run whenever they are triggered by an event. These triggers can be automatic events or manual triggers or even be defined on a recurring schedule. 

Each repository can have multiple workflows that perform various tasks for your teams. One workflow may help build and test pull requests, another might add a label when users open a new issue, and another could be used to deploy applications whenever releases are available automatically. 

Events

When it comes to GitHub Actions in Azure, an event is what triggers a workflow to run. Events can be any activity that you specify in a repository to trigger a set of jobs within a workflow. When one of your chosen events occurs, your triggered activity will originate from GitHub according to your unique configuration. 

There are innumerable events that you can use to execute crucial workflows, like when a user opens an issue, creates a new pull request, or pushes a commit to the repository. Events can also be in the form of a schedule. When a certain date, time, or development milestone is met, your scheduled workflow will run. 

Runners

Before we get too much further, it’s important that we discuss runners. A runner is a server that runs your triggered workflows, and each runner only runs one job at a time. GitHub provides runners for Azure so that each workflow runs in a clean virtual machine. 

You can take advantage of the larger runners that GitHub offers for more complex configurations. Or you can also host your own runners to create a custom configuration. Runners are a bit outside of the scope of this article, but they play a crucial role in running GitHub Actions. 

Jobs

A job refers to the steps within a workflow that are executed on the same runner. Each job describes a shell script to execute or an action that runs when an event triggers a workflow. Once the event tells the workflow to commence, it will start running each job according to your configuration. In other words, each step depends on the other, so they will be executed by order of dependency.

Jobs run parallel by default, so you will have to configure each job’s dependencies so that actions are executed at just the right time. For example, let’s say you are working on multiple build jobs with no dependencies. These jobs will run parallel at the same time. However, if you have a packaging job dependent on the build jobs, it will run whenever its dependencies are complete. 

Actions

Now, let’s talk about actions. GitHub Actions are custom applications that help DevOps teams perform frequently repeated tasks. Unlike other common workflow automations, GitHub Actions can perform complicated tasks to streamline your building and deployment processes. You can either write your own actions for a tailor-made experience or choose Actions from the GitHub Marketplace. 

There are numerous possibilities of what Actions can do for your Azure environment. For example, you can use Actions to pull git repositories from GitHub or set up the best toolchain for your unique building environment. You can even use GitHub actions for administrative things like setting up the authentication protocols for your cloud provider. 

Using GitHub Actions for Azure

Now that you know the basics of GitHub Actions, let’s discuss how to use it effectively with Azure. When it comes to Actions for Azure, you are only limited by the requirements of your projects. There are multiple ways that your teams can take advantage of automated actions in your Azure environment.

Let’s take a look at a handful of ways that GitHub Actions can be used with Azure:

Connect GitHub Actions and Azure

All you have to do to connect GitHub Actions to Azure is use a service principal. Alternatively, you can publish a profile to connect to Azure via GitHub. You’ll have to use a service principal every time you use the Azure login Action, but you can use it with most Actions for Azure to simplify your tasks. 

Authenticate from Azure to GitHub

You can also use Azure login with PowerShell and CLI to interact with your Azure resources in a GitHub Actions workflow. There are two different ways you can choose from. You can either authenticate through a service principal with secrets or via OpenID Connect. 

Deploy Apps from GitHub to Azure

It’s easy to deploy apps from GitHub to Azure with the App Service Deployment Center. This method will automatically generate a workflow based on your sack and commit it to your repository correctly. Alternatively, you can deploy apps from GitHub to Azure using a manual workflow. 

Deploy Databases from GitHub to Azure

You can also deploy databases from GitHub to Azure. Actions can be used to deploy databases to Azure SQL, Azure MySQL, and Azure Database for PostgreSQL. Each database has its own deployment method with Actions to make the process fast and easy. 

Use Variable Substitution with GitHub Actions

Variable substitution Actions can be used to replace values in configuration and parameter files. For example, you can use these actions to insert values like GitHub secrets into files during a workflow run. As long as the variable is defined as an environment variable or is otherwise available, variable substitution actions can run on Azure. 

Manage Azure Policies with GitHub

GitHub Actions also provide teams with various ways to manage Azure policies. For example, you can use GitHub Actions to export Azure policies from Azure, manage Azure policies as code via GitHub, and even trigger Azure compliance actions to simplify every stage of the development lifecycle. 

Build Custom Virtual Machine Images with GitHub Actions and Azure

If you want a truly customized experience, you can create a workflow to build a virtual machine image using GitHub Actions for Azure. To speed up your CI/CD processes, you can create custom virtual machine images using artifacts from workflows that can be distributed to a shared image gallery. 

How to Customize Your Azure Workflow with GitHub Actions

One of the perks of using GitHub Actions for Azure is the workflow possibilities are virtually endless. You can check out the GitHub Marketplace to find Actions to add to your workflows, use Actions from your repository, or reference a container on Docker Hub.

Here’s how to find and customize actions:

Add an Action From GitHub Marketplace

If you’re just getting started with GitHub Actions for Azure, your first stop should be the GitHub Marketplace. While working in the workflow editor, navigate to the sidebar to find a new Action. You can search for a specific action or browse featured actions and categories. You’ll also be presented with a star rating so that you can find only the best actions to add to your Azure workflows. 

Add an Action to a Repository

If you’ve already got a collection of Actions in your repository, you can simply add an action to whatever you’re working on in the workflow editor. All you have to do is reference the action with one of these syntax paths: ‌{owner}/{repo}@{ref} or ./path/to/dir.

If the action you want is defined in a public repository outside your workflow file, reference the action with this syntax: {owner}/{repo}@{ref}.

Reference a Container on Docker Hub

Finally, you can also add a container action to your workflow. If you have an action defined in a Docker container image published to Docker Hub, you should reference the action with this syntax: docker://{image}:{tag}.

But before you reference any actions to your workflow file, be sure that you verify the code is secure before introducing it to your environment. 

Put Your Learnings into Action

Now that you’ve had a crash course on GitHub Actions for Azure, it’s time to put it into practice. There are many ways that your teams can use Actions to speed up development and delivery processes. Start by checking out some of the uses for GitHub Actions for Azure we mentioned here in the article; then, you can start customizing your own actions and workflows for a tailor-made Azure experience. 

Like this post? Share it!

Read More Articles

Make Git Easier, Safer &
More Powerful

with GitKraken
Visual Studio Code is required to install GitLens.

Don’t have Visual Studio Code? Get it now.

Team Collaboration Services

Secure cloud-backed services that span across all products in the DevEx platform to keep your workflows connected across projects, repos, and team members
Launchpad – All your PRs, issues, & tasks in one spot to kick off a focused, unblocked day. Code Suggest – Real code suggestions anywhere in your project, as simple as in Google Docs. Cloud Patches – Speed up PR reviews by enabling early collaboration on work-in-progress. Workspaces – Group & sync repos to simplify multi-repo actions, & get new devs coding faster. DORA Insights – Data-driven code insights to track & improve development velocity. Security & Admin – Easily set up SSO, manage access, & streamline IdP integrations.
winget install gitkraken.cli