跳到主要内容

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 vars and secrets have been created via the AtomGit UI (Path: Project Settings → Actions Secrets and Variables).
  • Understanding the differences between env, vars, secrets, and inputs.

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​

TypeSuitable ForSensitive?Definition LocationReference Syntax
envTemporary workflow variablesNoYAML file$APP_NAME or ${{ env.APP_NAME }}
varsRepo/Org-level standard configsNoAtomGit UI${{ vars.DEPLOY_TARGET }}
secretsPasswords, tokens, private keysYesAtomGit UI${{ secrets.REGISTRY_PASSWORD }}
inputsworkflow_dispatch / workflow_call parametersNoYAML 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 MethodSyntaxApplicable 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_NAMEUsed 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, but echo "${{ 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 VariableDescription
ATOMGIT_TOKENAutomatically generated workflow token
ATOMGIT_SHACurrent commit SHA
ATOMGIT_REFCurrent branch or tag reference
ATOMGIT_EVENT_NAMETrigger event name
ATOMGIT_REPOSITORYRepository identifier (owner/repo)
ATOMGIT_WORKSPACEWorking directory on the Runner
ATOMGIT_OUTPUTFile path for writing step outputs
ATOMGIT_ENVFile path for writing environment variables
ATOMGIT_PATHFile path for writing PATH updates
ATOMGIT_RUNNER_OSRunner operating system
ATOMGIT_RUNNER_ARCHRunner architecture

Priority Rules Overview​

From highest to lowest:

  1. Step-level env
  2. Job-level env
  3. Workflow-level env
  4. vars (Configuration Variables)
  5. System Variables (ATOMGIT_*)