Repository-level Environment Variables and Secrets in GitHub Actions

Search for a command to run...

No comments yet. Be the first to comment.
Introduction User access management is one of the most fundamental responsibilities in any infrastructure environment, yet it is often handled in an ad hoc and manual way. In many organizations, espec

Managing sensitive credentials like API keys across multiple GitHub repositories is challenging. It leads to duplicate secrets, a lack of versioning, and potential inconsistencies between environments. The solution is to use HashiCorp Vault Secrets o...

Introduction DevOps engineers today spend countless hours context-switching between dashboards, logs, cloud consoles, and documentation. Traditional AI tools like ChatGPT are great at answering questions, but they lack direct access to your infrastru...

When working with GitHub Actions, you may face situations where multiple workflow runs overlap, consume unnecessary resources, or even cause conflicts in deployment. This is where concurrency comes into play. Concurrency in GitHub Actions allows you ...

When teams scale, managing workflows across multiple repositories becomes more complex. Each project often shares common configuration values, cloud credentials, or deployment secrets. Instead of duplicating these across repositories, GitHub provides...

CloudDecode
11 posts
CloudDecode simplifies cloud & DevOps—covering Azure, AWS, Kubernetes, Terraform, CI/CD & more—with clear guides to help you decode, learn, and build with confidence.
When working with GitHub Actions, environment variables and secrets are powerful tools that help you configure workflows in a flexible and secure way. While workflow, job, and step-level variables are useful, sometimes you need variables that are available across all workflows in a repository. This is where repository-level environment variables and secrets come in.
In this article, we’ll break down how repository-level variables and secrets work, why they are useful, and how you can manage them effectively. We’ll also see how to use them in a real-world example: building and pushing a Docker image.
Repository-level environment variables are key-value pairs defined in your repository’s settings. They are accessible to all workflows in that repository, without needing to redefine them in every workflow file.
For example:
Common Docker tags
Application environment names (like STAGING, PROD)
URLs or constants that rarely change
They’re stored in plain text, so they are suitable for non-sensitive data.
Secrets are similar to variables, but they are encrypted and hidden. They are designed for storing sensitive data such as:
API keys
Database passwords
Cloud provider credentials
DockerHub tokens
Secrets are masked in logs and cannot be retrieved once set, making them the secure way to pass sensitive information into workflows.
Go to your GitHub repository.
Navigate to:
Settings → Secrets and variables → Actions
You’ll find two tabs:
Variables → for non-sensitive values
Secrets → for sensitive values
Add your desired key-value pairs.
For example:
Variable: DOCKER_IMAGE_NAME = myapp
Secret: DOCKERHUB_TOKEN = <your token>
Once defined, you can access these directly in your YAML workflow:
name: Docker Build and Push
on: [push]
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Log in to DockerHub
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USER }} --password-stdin
- name: Build Docker image
run: docker build -t ${{ vars.DOCKER_IMAGE_NAME }}:${{ github.sha }} .
- name: Push Docker image
run: docker push ${{ vars.DOCKER_IMAGE_NAME }}:${{ github.sha }}
Use repository-level variables for constants that don’t need to be hidden.
Use secrets for anything sensitive.
Variables are available using ${{ vars.NAME }}.
Secrets are available using ${{ secrets.NAME }}.
Both variables and secrets are available in all workflows in the repository.
Imagine you’re deploying a service using DockerHub. Instead of hardcoding image names and credentials in multiple workflow files:
Store DOCKER_IMAGE_NAME as a variable.
Store DOCKERHUB_USER and DOCKERHUB_TOKEN as secrets.
Reference them directly in your workflows.
This keeps your workflows clean, reusable, and secure.
Repository-level variables and secrets are essential for building maintainable and secure GitHub Actions workflows. They allow you to centralize configuration, avoid duplication, and keep sensitive data safe. Whether you’re building Docker images, deploying to cloud services, or running CI pipelines, understanding how to use repository-level variables and secrets will save you time and headaches.