Scroll to top
© 2024, Global Digital Services LLC.

Integrate Github Action with Azure Blob Storage


Fernando Noguera - September 20, 2022 - 0 comments

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline, you can create workflows that build and test every pull request to your repository, or deploy merged pull requests to production.

The Components of GitHub Actions

You can configure a GitHub Actions workflow to be triggered when an event occurs in your repository, such as a pull request being opened or an issue being created. Your workflow contains one or more jobs which can run in sequential order or in parallel. Each job will run inside its own virtual machine runner, or inside a container, and has one or more steps that either run a script that you define or run an action, which is a reusable extension that can simplify your workflow.

Workflows

A workflow is a configurable automated process that will run one or more jobs. Workflows are defined by a YAML file and the .github/workflows directory in a repository, and a repository can have multiple workflows, each of which can perform a different set of tasks.

Events

An event is a specific activity in a repository that triggers a workflow run. For example, activity can originate from GitHub when someone creates a pull request, opens an issue, or pushes a commit to a repository.

Jobs

A job is a set of steps in a workflow that execute on the same runner. Each step is either a shell script that will be executed, or an action that will be run.

Actions

An action is a custom application for the GitHub Actions platform that performs a complex but frequently repeated task.

Runners

A runner is a server that runs your workflows when they’re triggered.

Quick start with Github Action and Azure

Lets make a simple demo to understand how you can use Github Action and Azure, in this demo we are going to create an Azure Blob Storage and github repository, and configure a github action that will upload a file from the github repository to the Azure Blob Storage everytime there is a commit.

Prerequisites:

  • Azure Account, If you don’t have an Azure subscription, create a free account before you begin.
  • Create a Azure Blob Storage Account, if you don’t have it, visit this post.
  • Create a repository in github or clone this repository.

First, create the secrets to authenticate with Azure and establish the connection, with the next command to assign permissions for the resource group

        az ad sp create-for-rbac --name {myApp} --role contributor --scopes /subscriptions/{subscription-id}/resourceGroups/{MyResourceGroup} --sdk-auth

        In this demo will be like this,

        az ad sp create-for-rbac --name githubaction --role contributor --scopes /subscriptions/safdfdsfds555-554fs-87529-7sfs5-sddssd5552ds44d/resourceGroups/testgroup --sdk-auth

        Next, using as reference a previous post we configure Azure secrets,

        AZURE_CREDENTIALS = {
        "clientId": "xxs-xxxxxssx-xxxx- xxxxxxx",
        "clientSecret": "dhdhhdjd-dkdkdjdjkll-l-ldldldñd{ d",
        "subscriptionId": "jdjdkddñ - kdkdhdjkd -dldldkdkf",
        "tenantId": "ksdjshfsf-lsjfjskf-lsfkjfjskfs",
        "activeDirectoryEndpointUrl": "https://login.microsoftonline.com",
        "resourceManagerEndpointUrl": "https://management.azure.com/",
        "activeDirectoryGraphResourceId": "https://graph.windows.net/",
        "sqlManagementEndpointUrl": "https://management.core.windows.net:8443/",
        "galleryEndpointUrl": "https://gallery.azure.com/",
        "managementEndpointUrl": "https://management.core.windows.net/"
        }
        AZURE_STORAGE_ACCOUNT = test01234
        AZURE_STORAGE_ACCESS_KEY=kF+69oE3+ox90bU1gQZIsacJZe5fhOEESCxadUmU0LMxMY6qe9Y3Mtg/Fl89kh9grlSP527rYqK7+AStQoa/+w==
        AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=https;EndpointSuffix=c* ore.windows.net;AccountName=test01234;AccountKey=kF+69oE3+ox90bU1gQZIsacJZe5fhOEESCxadUmU0LMxMY6qe9Y3Mtg/Fl89kh9grlSP527rYqK7+AStQoa/+w=="

        Add a directoy in the repository .github\workflows and create a file with the pipeline’s YAML configuration for this example upload a text file to Azure Blob Storage,

        Commit and push the file to the project’s Git repository, check if the github action worked properly

        Finally check in the azure portal if the file was uploaded successfully,

        Contact us for more information or visit our blog.

        Related posts