Using Variables and Secrets
This document explains how to define four types of variables in workflows (env, vars, secrets, inputs), along with their scoping rules, priority hierarchy, and security considerations.
Prerequisites
- Required
varsandsecretshave been created via the AtomGit UI (Path: Project Settings → Actions Secrets and Variables). - Understanding the differences between
env,vars,secrets, andinputs.
Quick Example
name: ci-with-vars
on:
push:
branches:
- main
workflow_dispatch:
inputs:
environment:
description: "Deployment Environment"
type: string
default: test
env:
APP_NAME: demo-app
jobs:
build:
name: Build
runs-on: [ubuntu-latest, x64, small]
env:
BUILD_MODE: release
steps:
- name: Checkout source code
uses: checkout
- name: Print variables
env:
STEP_VAR: step-level
run: |
echo "APP_NAME=$APP_NAME"
echo "BUILD_MODE=$BUILD_MODE"
echo "STEP_VAR=$STEP_VAR"
echo "CONFIG_VAR=${{ vars.DEPLOY_TARGET }}"
echo "SHA=${{ atomgit.sha }}"
- name: Use secret
env:
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: echo "password is masked"
Configuration Details
Four Variable Types
| Type | Suitable For | Sensitive? | Definition Location | Reference Syntax |
|---|---|---|---|---|
env | Temporary workflow variables | No | YAML file | $APP_NAME or ${{ env.APP_NAME }} |
vars | Repo/Org-level standard configs | No | AtomGit UI | ${{ vars.DEPLOY_TARGET }} |
secrets | Passwords, tokens, private keys | Yes | AtomGit UI | ${{ secrets.REGISTRY_PASSWORD }} |
inputs | workflow_dispatch / workflow_call parameters | No | YAML file | ${{ inputs.environment }} |
env Environment Variables
env supports three levels of scope: Workflow-level → Job-level → Step-level
env:
APP_NAME: demo-app # Workflow-level, visible to all jobs and steps
jobs:
build:
name: Build
runs-on: [ubuntu-latest, x64, small]
env:
BUILD_MODE: release # Job-level, visible to all steps within this job
steps:
- name: Print env
env:
STEP_VAR: step-level # Step-level, visible only to this specific step
run: echo "$STEP_VAR"
Priority Rules: Step-level > Job-level > Workflow-level. Variables at the Step level with the same name override those at the Job and Workflow levels.
Referencing in YAML vs. in the Runner:
| Reference Method | Syntax | Applicable Scenario |
|---|---|---|
| Referencing in YAML (Expression) | ${{ env.APP_NAME }} | Used directly in YAML fields; evaluated and replaced before the Runner executes |
| Referencing in Runner (Env Variable) | $APP_NAME | Used inside run commands; interpreted by the Shell |
vars Configuration Variables
vars are created via the AtomGit UI and support both repository-level and organization-level scopes:
steps:
- name: Use config variable
run: echo "deploy to ${{ vars.DEPLOY_TARGET }}"
Creation Path: Project Settings → Actions Secrets and Variables → Repository Variables → Create New Repository Variable
secrets Secrets
secrets are encrypted when created via the AtomGit UI and are automatically masked in logs as ***:
steps:
- name: Login registry
env:
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: |
echo "$REGISTRY_PASSWORD" | docker login example.com -u "$REGISTRY_USERNAME" --password-stdin
Security Tips:
- Avoid printing secrets in logs (
echo "$SECRET"will be masked in logs, butecho "${{ secrets.MY_SECRET }}"might bypass masking).- Do not write secrets to artifacts or caches.
- PRs/MRs from external contributors should not expose high-privilege secrets by default.
System Variables
System variables for AtomGit Actions use the ATOMGIT_* prefix:
| System Variable | Description |
|---|---|
ATOMGIT_TOKEN | Automatically generated workflow token |
ATOMGIT_SHA | Current commit SHA |
ATOMGIT_REF | Current branch or tag reference |
ATOMGIT_EVENT_NAME | Trigger event name |
ATOMGIT_REPOSITORY | Repository identifier (owner/repo) |
ATOMGIT_WORKSPACE | Working directory on the Runner |
ATOMGIT_OUTPUT | File path for writing step outputs |
ATOMGIT_ENV | File path for writing environment variables |
ATOMGIT_PATH | File path for writing PATH updates |
ATOMGIT_RUNNER_OS | Runner operating system |
ATOMGIT_RUNNER_ARCH | Runner architecture |
Priority Rules Overview
From highest to lowest:
- Step-level
env - Job-level
env - Workflow-level
env vars(Configuration Variables)- System Variables (
ATOMGIT_*)