How to Use Secrets in GitHub Actions Workflows

In this blog post, we will see how to use secrets in GitHub Actions workflows and protect sensitive information.

Secrets

To create a secret in GitHub actions, please refer to this blog post where we created a secret. In GitHub, we have two types of secrets, the first is a repo level secret, and the second is organisation level.

Once a secret has been created we access it using the following code.

${{ secrets.secret_name }}

Example

The following example shows how I use a secret to login into Microsoft Azure.

on: [push]

name: Azure Login

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Log in to Azure
        uses: azure/login@v1
        with:
          creds: '${{ secrets.AZURE_CREDENTIALS }}'
          enable-AzPSSession: true

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.