Appearance
GitHub Actions, GitLab CI and Azure Pipelines
243. What are GitHub Actions workflows, jobs, steps, runners, actions, and reusable workflows?
The short answer
A workflow is a YAML file in .github/workflows/ that runs when an event happens, such as a push. It contains jobs, and each job runs on its own runner, a fresh machine, with jobs running in parallel unless told otherwise. A job is a list of steps that run in order on that runner. A step either runs a shell command or uses an action, a reusable, packaged unit of steps. A reusable workflow is a whole workflow that other workflows can call like a single job.
needs. Inside a job, steps run in order and share one machine.yaml
name: ci # the workflow
on: [push] # the event that starts it
jobs:
build: # a job
runs-on: ubuntu-latest # the runner it needs
steps:
- uses: actions/checkout@v4 # a step using an action
- run: npm ci && npm run build # a step running a command
deploy:
needs: build # waits for build
runs-on: ubuntu-latest
steps:
- run: ./deploy.sh stagingActions come in three kinds: written in JavaScript, packaged as a container image, or composite, a list of steps in YAML (question 247). Most come from the GitHub Marketplace. Because an action runs inside your job with access to your token and secrets, pin third-party actions to a full commit SHA, such as uses: some/action@8f4b7f84..., rather than a tag that could be moved (question 273).
Reusable workflows are called from a job:
yaml
jobs:
build:
uses: shop/pipelines/.github/workflows/node-service.yml@v3
with: { service: checkout-api }
secrets: inheritThe called workflow's own jobs run in its place. secrets: inherit passes the caller's secrets on to it. Question 247 compares reusable workflows with composite actions.
244. What is the difference between needs, job dependencies, and step ordering in GitHub Actions?
The short answer
Steps inside a job always run one after another, in the order written, on the same runner. Jobs run in parallel by default, each on its own runner. needs is how you create a dependency between jobs: a job with needs: build waits until build succeeds, is skipped if it fails, and can read values that build declared as outputs.
yaml
jobs:
build:
runs-on: ubuntu-latest
outputs:
digest: ${{ steps.push.outputs.digest }} # (1)
steps:
- uses: actions/checkout@v4
- id: push
uses: docker/build-push-action@v6
with: { push: true, tags: "myacr.azurecr.io/shop/api:${{ github.sha }}" }
scan:
needs: build # (2)
runs-on: ubuntu-latest
steps:
- run: trivy image myacr.azurecr.io/shop/api@${{ needs.build.outputs.digest }} # (3)
notify:
needs: [build, scan]
if: ${{ always() }} # (4)
runs-on: ubuntu-latest
steps:
- run: echo "build=${{ needs.build.result }} scan=${{ needs.scan.result }}"builddeclares an output, the image digest, taken from one of its steps.scandepends onbuild: it starts only afterbuildfinishes successfully.- It reads
build's output through theneedscontext. This is the only way jobs pass small values to each other, because each job runs on a different machine. notifymust run even if something failed, so it overrides the default condition withalways(), and reports each job's result:success,failure,cancelledorskipped.
| Steps | Jobs | needs | |
|---|---|---|---|
| Run in order | Always | No, parallel by default | Creates an order |
| Same machine | Yes | No | Not applicable |
| Share files | Yes, the workspace | No, use artifacts | Outputs only, or artifacts |
| On failure | Later steps are skipped | Other jobs continue | Dependent jobs are skipped |
Passing files between jobs needs artifacts, actions/upload-artifact and actions/download-artifact (question 249), because each job's runner starts with an empty workspace.
245. How do GitHub Actions triggers and branch filters determine when a workflow runs?
The short answer
The on: section lists the events that can start the workflow, such as push, pull_request, schedule or workflow_dispatch. Filters then narrow each event down: branches and tags match which branch or tag the event is about, paths match which files changed, and types match which kind of activity happened. The workflow runs only if an event matches and all of its filters agree.
yaml
on:
push:
branches: [main, 'release/**'] # (1)
tags: ['v*'] # (2)
paths-ignore: ['docs/**', '**.md'] # (3)
pull_request:
branches: [main] # (4)
types: [opened, synchronize, reopened]
paths: ['services/checkout-api/**'] # (5)
schedule:
- cron: '30 2 * * *' # (6)
workflow_dispatch: # (7)- Pushes to
main, or to any branch underrelease/.**matches any depth of slashes. - Pushes of tags starting with
v, such asv1.4.2. - Skip the run if the push changed only documentation.
- For pull requests,
branchesmatches the target branch, the one the pull request wants to merge into, not the pull request's own branch. This is a frequent surprise. - Only pull requests that touch the checkout service.
- Every day at 02:30 UTC. Scheduled workflows run only from the repository's default branch.
- Adds a "Run workflow" button for manual starts.
Rules that catch people out:
- The workflow file must exist in the branch or commit involved. A new workflow file on a feature branch runs for that branch's pushes, but a
scheduleonly uses the default branch's copy. - Path filters and required checks. If a workflow is skipped by a path filter, its check never reports. If branch protection requires that check, the pull request waits forever. The fix is a job that always runs and decides inside the job whether to do the real work.
- Pushes with many commits. Path filters look at all the changes in the push, up to a limit.
- Events from other workflows. Actions taken using the workflow's own built-in token, such as pushing a commit, deliberately do not start new workflow runs, which prevents endless loops.
246. How should secrets and environment protection rules be configured in GitHub Actions?
The short answer
Store secrets at the narrowest level that works: environment secrets for deployment credentials, repository secrets for repository-wide values, and organisation secrets only for values shared across chosen repositories. Put production credentials on a production environment protected by required reviewers and a rule that only the main branch may deploy to it. Give the built-in token minimal permissions. And prefer OIDC over stored cloud keys, so there is no long-lived secret at all.
Where secrets can live:
| Level | Visible to | Use for |
|---|---|---|
| Organisation | Selected repositories | Shared, low-risk values |
| Repository | All workflows in the repository | Values every job needs |
| Environment | Only jobs that use that environment, after its rules pass | Deployment credentials |
An environment with protection rules, set in the repository's settings, can require:
- Required reviewers: named people or teams must approve each deployment job before it starts. Admins can stop authors from approving their own runs.
- A wait timer, such as 10 minutes after approval.
- Deployment branches and tags: only
main, or only tags matchingv*, may deploy to it. - Custom rules from apps, for example a change-management system that must say yes.
The environment's secrets are released to a job only after these rules pass.
yaml
permissions:
contents: read # (1)
jobs:
deploy-prod:
runs-on: ubuntu-latest
environment:
name: production # (2)
url: https://shop.example.com
permissions:
contents: read
id-token: write # (3)
steps:
- uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- run: ./deploy.sh production
env:
PAYMENT_WEBHOOK_KEY: ${{ secrets.PAYMENT_WEBHOOK_KEY }} # (4)- The built-in
GITHUB_TOKENcan only read, unless a job asks for more. - The job uses the
productionenvironment, so its protection rules apply before it starts. - Lets this job request an OIDC token, so it can log in to Azure with no stored password (question 269). The IDs passed to the login step are not secrets, which is why they are stored as variables.
- An environment secret, passed to the one step that needs it, as an environment variable.
GitHub masks secret values in logs, but, as with Jenkins, masking only hides exact matches. Never print secrets or turn on shell tracing (question 270).
247. What is the difference between a composite action, a reusable workflow, and a workflow template?
The short answer
A composite action bundles several steps into one step that you use inside your own job, on your job's runner. A reusable workflow bundles whole jobs, with their own runners, environments and secrets, and is called in place of a job. A workflow template, also called a starter workflow, is not linked at all: it is a file that GitHub offers to copy into a new repository, and later changes to the template do not reach the copies.
| Composite action | Reusable workflow | Workflow template | |
|---|---|---|---|
| Bundles | Steps | Jobs | A whole workflow file |
| Used as | A step: uses: in steps | A job: uses: under jobs | A copy made once |
| Runs on | The caller's runner | Its own runners | Wherever the copy says |
| Own environments and secrets | No | Yes | Yes, in the copy |
| Updates reach users | Yes, when they bump the version | Yes, when they bump the version | No |
| Typical use | "Set up Node with our cache settings" | "Our standard build and deploy pipeline" | "Start new repositories with this" |
A composite action, kept at .github/actions/setup-node-cached/action.yml:
yaml
name: setup-node-cached
inputs:
node-version: { default: '20' }
runs:
using: composite
steps:
- uses: actions/setup-node@v4
with: { node-version: "${{ inputs.node-version }}", cache: npm }
- run: npm ci
shell: bashUsed inside any job as one step: - uses: ./.github/actions/setup-node-cached. Steps in a composite action that run commands must state their shell.
A reusable workflow declares on: workflow_call with its inputs and secrets, and a caller uses it as a job (question 243).
A workflow template lives in the organisation's special .github repository, under workflow-templates/. When someone creates a new workflow, GitHub offers it as a starting point. Because the result is a copy, templates do not help with keeping repositories consistent later. Reusable workflows do (question 259).
248. How do matrix builds help test different language, operating-system, or runtime versions?
The short answer
A matrix runs the same job several times, once for each combination of values you list, such as every pair of operating system and Node.js version, all in parallel. One job definition then checks a library on Linux, Windows and macOS with three runtime versions, nine runs in all. You can add or remove specific combinations, choose whether one failure cancels the rest, and limit how many run at once.
yaml
jobs:
checks:
strategy:
fail-fast: false # (1)
max-parallel: 6 # (2)
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [18, 20, 22] # (3)
exclude:
- os: macos-latest
node: 18 # (4)
include:
- os: ubuntu-latest
node: 22
coverage: true # (5)
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: "${{ matrix.node }}" }
- run: npm ci && npm run unit
- if: ${{ matrix.coverage }}
run: npm run coverage- Keep running the other combinations if one fails, so you see every failure at once, not just the first.
- Run at most six at a time, to share runners fairly.
- Three operating systems times three versions: nine combinations.
- Remove one combination nobody needs.
- Add an extra value to an existing combination. Only the Linux and Node.js 22 run measures coverage.
What matrices are good for:
- Libraries and tools used by others on many platforms and versions.
- Upgrade checks, such as running the current and the next runtime version side by side before switching.
- Splitting work, using a matrix of shard numbers (question 224).
What to watch: every combination costs runner time. macOS and Windows runners are usually charged at a higher rate than Linux. A service that only ever runs on one Linux image in production rarely needs a large matrix.
249. How do GitHub Actions cache and artifact upload and download mechanisms differ?
The short answer
A cache is for speed: it stores files such as downloaded packages under a key, so later workflow runs can restore them, and it may be evicted at any time. An artifact is for results. It stores files a run produced, such as a built binary or a report. Later jobs in the same run, or people, can download them. It is kept for a set number of days. Caches are best-effort and shared across runs; artifacts belong to one run and are reliable for its jobs.
Cache (actions/cache) | Artifact (upload-artifact, download-artifact) | |
|---|---|---|
| Purpose | Make runs faster | Pass outputs on, keep results |
| Shared across workflow runs | Yes, by key | No, belongs to one run |
| Guaranteed to exist | No | Yes, until it expires |
| Removed | When unused for a while, or when storage is full | After the retention period |
| Typical contents | ~/.npm, ~/.m2, Docker layers | dist/, check reports, SBOMs |
| Who uses it | Later runs | Later jobs in the same run, and people |
A cache:
yaml
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-${{ runner.os }}-${{ hashFiles('requirements.txt') }}An artifact passed between jobs:
yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: npm ci && npm run build
- uses: actions/upload-artifact@v4
with: { name: web-dist, path: dist/, retention-days: 7 }
e2e:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with: { name: web-dist, path: dist/ }
- run: npx serve dist & npm run e2eThe rule from question 218 applies: never make a deployment depend on a cache. Use an artifact to pass outputs within a run, and a real artifact repository or registry for anything that must outlive the run (question 216).
250. How would you prevent an untrusted pull request from accessing production credentials in GitHub Actions?
The short answer
Rely on GitHub's defaults and do not weaken them: workflows triggered by pull_request from a fork get a read-only token and no secrets. Never use pull_request_target or workflow_run to build or run the pull request's code, because those run with the base repository's secrets. Keep production credentials in an environment that only the main branch can use, and that needs approval. Bind OIDC trust to main, or to that environment. Require approval before outsiders' workflows run. Never run public pull requests on self-hosted runners.
1. Keep the defaults. For pull_request events from forks, GitHub gives the workflow a read-only token and passes no secrets. That is exactly right for unreviewed code.
2. Understand the dangerous triggers. pull_request_target runs the workflow from the base repository, with its secrets and a write-capable token, so that it can, for example, label pull requests. If such a workflow checks out the pull request's code and runs it, for example npm install with the attacker's package.json, the attacker's code runs with your secrets. This pattern has caused real breaches. workflow_run workflows carry the same risk if they process files produced by the pull request.
3. Require approval for outsiders. Repository settings can require a maintainer to approve workflow runs from first-time or outside contributors before they run at all.
4. Guard production with an environment. Production credentials live only in the production environment, which allows deployments only from main and needs reviewers (question 246).
5. Bind cloud trust to main. With OIDC, the cloud trusts tokens whose subject is, for example, repo:shop/checkout-api:environment:production. A token from a pull request has a different subject, so the cloud refuses it, even if everything else went wrong (question 269).
6. No self-hosted runners for public pull requests. Strangers' code would run inside your network (question 272).
7. Avoid script injection. Values such as a pull request's title are controlled by its author. Pasting them directly into a run: line lets a crafted title run commands. Pass them through an environment variable instead (question 270):
yaml
- run: echo "Title: ${{ github.event.pull_request.title }}" # unsafe: pasted into the script
- run: echo "Title: $PR_TITLE" # safe: the shell reads it as data
env:
PR_TITLE: ${{ github.event.pull_request.title }}251. What are GitLab CI stages, jobs, runners, artifacts, caches, and needs?
The short answer
In a .gitlab-ci.yml file, stages are ordered groups, such as build, check and deploy, and all jobs in one stage run in parallel after the previous stage finishes. A job is a named set of commands that belongs to a stage. Runners are the machines that run jobs, chosen by tags. Artifacts are files a job passes to later jobs, kept by GitLab. Caches are files kept only to speed up later runs. needs lets a job start as soon as the specific jobs it depends on finish, instead of waiting for the whole previous stage.
yaml
stages: [build, check, deploy] # (1)
build:
stage: build
image: node:20-slim # (2)
tags: [linux, docker] # (3)
cache:
key:
files: [package-lock.json]
paths: [.npm/] # (4)
script:
- npm ci --cache .npm
- npm run build
artifacts:
paths: [dist/]
expire_in: 1 week # (5)
lint:
stage: check
needs: [] # (6)
script: [npm ci --cache .npm, npm run lint]
e2e:
stage: check
needs: [build] # (7)
script: [npm run e2e]
deploy-staging:
stage: deploy
needs: [build, e2e]
environment: staging
script: [./deploy.sh staging]- The order of stages.
- With the Docker or Kubernetes executor, the job runs inside this image.
- Only runners carrying both tags may run it.
- A cache keyed on the lock file, for npm's downloads.
- The
dist/folder is uploaded to GitLab and available to later jobs for a week. needs: []means "depends on nothing", so lint starts immediately, alongside build, even though it sits in a later stage.e2estarts as soon asbuildfinishes, and downloads its artifacts, without waiting for other jobs.
With needs, the pipeline becomes a graph, sometimes called a DAG, a directed acyclic graph: jobs connected by "must run after" arrows with no loops. Jobs run as early as their own dependencies allow, which often makes pipelines much faster than strict stage-by-stage order.
252. How do GitLab CI rules, only/except, and workflow rules affect pipeline execution?
The short answer
rules decide, job by job, whether a job is added to a pipeline and how it runs. They are checked in order, and the first one that matches wins, setting when to run normally, wait for a manual click, or never run. only and except are the older, simpler way to do the same thing, and should not be mixed with rules in one job. workflow: rules work one level up: they decide whether a whole pipeline is created at all.
Job rules:
yaml
deploy-prod:
stage: deploy
script: [./deploy.sh production]
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/ # (1)
when: manual # (2)
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never # (3)
- when: never # (4)
checkout-api-checks:
script: [make -C services/checkout-api check]
rules:
- changes:
paths: [services/checkout-api/**/*, libs/money/**/*]
compare_to: refs/heads/main # (5)- If the pipeline is for a version tag such as
v1.4.2. - Add the job, but wait for someone to start it by hand.
- Never in scheduled pipelines.
- In every other case, do not add the job. Without this last line, a job whose rules all fail to match is simply not added, so this line makes the intent explicit.
- Only add the job when files under these paths changed, compared with main (question 255).
Workflow rules, for the whole pipeline:
yaml
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" # (1)
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never # (2)
- if: $CI_COMMIT_BRANCH # (3)- Create pipelines for merge requests.
- But do not create a separate branch pipeline for a branch that already has an open merge request. This avoids the classic problem of two duplicate pipelines for every push.
- Create pipelines for other branch pushes.
only and except say the same kind of thing more simply, for example only: [main]. They cannot express everything rules can, and GitLab recommends rules for new configuration.
253. What is the difference between a GitLab cache and a GitLab artifact?
The short answer
An artifact is a job's output, uploaded to GitLab, guaranteed to be available to later jobs in the same pipeline, and downloadable from the interface until it expires. A cache is a speed-up, files such as downloaded dependencies kept between pipelines, which may or may not be found next time, and by default is stored on the runner itself. Use artifacts to pass results on, and caches only to save time.
| Cache | Artifact | |
|---|---|---|
| Purpose | Speed | Passing results, keeping outputs |
| Stored | On the runner, or a shared cache bucket if configured | In GitLab |
| Available to | Later jobs and pipelines that find it | Later jobs in the same pipeline, and people |
| Guaranteed | No | Yes, until expire_in |
| Typical contents | .npm/, .m2/, vendor/ | dist/, reports, packages |
Two GitLab details that matter:
- Caches live on runners by default. If you have five runners, a job may land on a runner that never saw the cache. For caches shared by all runners, configure a distributed cache in object storage, such as S3 or Azure Blob storage, in the runners' settings.
- Choosing which artifacts to download. By default, a job downloads the artifacts of every job in earlier stages.
dependencies: [build], orneedswith a list, limits that to what the job actually uses, which saves time on big pipelines.
Artifact reports are a special kind of artifact that GitLab reads and shows in the merge request, such as check results, coverage and security scan reports:
yaml
unit:
script: [npm run unit -- --reporter=junit --outputFile=report.xml]
artifacts:
reports:
junit: report.xml254. How do GitLab environments, deployment jobs, and protected environments support controlled releases?
The short answer
A job that names an environment becomes a deployment job. GitLab records every deployment to that environment: which commit, which job, who started it, and when, so you get a history and a one-click way to re-run an earlier deployment as a rollback. Protected environments restrict who may deploy to an environment, such as production, and can require approvals. Resource groups make deployments to one environment run one at a time.
yaml
deploy-prod:
stage: deploy
script: [./deploy.sh production]
environment:
name: production # (1)
url: https://shop.example.com
resource_group: production # (2)
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual # (3)
review-app:
stage: deploy
script: [./deploy-review.sh "$CI_MERGE_REQUEST_IID"]
environment:
name: review/$CI_COMMIT_REF_SLUG # (4)
url: https://$CI_COMMIT_REF_SLUG.review.shop.example.com
on_stop: stop-review-app
auto_stop_in: 2 days
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"- A deployment job for
production, linked to its live address. - Only one job at a time may use the
productionresource group, so deployments never overlap (question 222). - A manual start, from the default branch only.
- A review app: a temporary environment for each merge request, with its own address, stopped automatically after two days or when the merge request closes.
Protected environments, configured in the project's settings, let you:
- Allow deployments to
productiononly by certain roles, groups or people. - Require one or more approvals before a deployment job may run.
- Keep environment-specific variables, such as production credentials, available only to jobs deploying there.
Rollback is simple: the environment's page lists past deployments, and re-running an earlier one redeploys that version.
255. How would you configure a pipeline to run only for changed directories in a monorepo?
The short answer
Use the platform's change filters on each service's jobs: rules: changes with compare_to in GitLab, paths filters or a path-filtering step in GitHub Actions. Include each service's shared dependencies in its filter. For larger monorepos, generate the pipeline dynamically, for example GitLab child pipelines per changed service, or use a build tool that knows the dependency graph. Watch two traps: events with nothing to compare against, and required checks that never report when skipped.
GitLab: one job per service, filtered by changes.
yaml
checkout-api:
script: [make -C services/checkout-api build check]
rules:
- changes:
paths:
- services/checkout-api/**/*
- libs/money/**/*
compare_to: refs/heads/maincompare_to makes GitLab compare against main, rather than only against the previous push, so all of a branch's changes are considered.
GitHub Actions: decide inside a job that always runs.
yaml
jobs:
changes:
runs-on: ubuntu-latest
outputs:
checkout: ${{ steps.filter.outputs.checkout }}
steps:
- uses: actions/checkout@v4
- id: filter
uses: dorny/paths-filter@v3 # (1)
with:
filters: |
checkout:
- 'services/checkout-api/**'
- 'libs/money/**'
checkout-api:
needs: changes
if: ${{ needs.changes.outputs.checkout == 'true' }} # (2)
runs-on: ubuntu-latest
steps:
- run: echo "build and check checkout-api"- A widely used community action that reports which groups of paths changed.
- The service job runs only if its paths changed. Because the
changesjob always runs, the workflow always reports a status, which avoids the "required check never reported" trap from question 245.
For many services: dynamic pipelines. A first job works out which services changed, then generates and starts a pipeline for each. In GitLab this is a child pipeline, started with trigger: include: from a generated file. A dependency-aware tool such as Nx or Bazel can do the "what changed" part properly, including services that depend on a changed library (question 193).
Trap: nothing to compare against. A brand-new branch, a tag or a scheduled pipeline may have no previous state to compare with. GitLab then treats change rules as matching, so everything runs. That is the safe default, but expect it.
256. How do Azure Pipelines stages, jobs, tasks, agents, variable groups, and environments fit together?
The short answer
An Azure Pipelines YAML file has stages, which run in order, such as Build, then Deploy to staging, then Deploy to production. Each stage has jobs, and each job runs on an agent taken from an agent pool. A job is a list of steps, which are either scripts or tasks, the pre-built steps from Microsoft or the marketplace. Variable groups hold shared variables, optionally linked to Azure Key Vault. Environments represent deployment targets, with their own approvals, checks and deployment history.
yaml
trigger:
branches: { include: [main] }
variables:
- group: shop-common # (1)
- name: imageRepo
value: shop/checkout-api
stages:
- stage: Build
jobs:
- job: build
pool: { vmImage: ubuntu-latest } # (2)
steps:
- task: Docker@2 # (3)
inputs:
command: buildAndPush
containerRegistry: acr-connection # (4)
repository: $(imageRepo)
tags: $(Build.SourceVersion)
- stage: DeployProd
dependsOn: Build
jobs:
- deployment: deploy # (5)
environment: production # (6)
pool: { vmImage: ubuntu-latest }
strategy:
runOnce:
deploy:
steps:
- script: ./deploy.sh production $(Build.SourceVersion)- A variable group: variables shared by many pipelines, managed in the Library. It can be linked to an Azure Key Vault, so secrets are read from the vault at run time.
- A Microsoft-hosted agent from the default pool. A self-hosted pool would be named with
pool: { name: shop-agents }. - A task: a packaged, versioned step, here the Docker task, which builds and pushes.
- A service connection: a stored, managed connection to an outside system, here the container registry. Service connections to Azure can use workload identity federation, which is Azure DevOps' name for OIDC, so no secret is stored (question 269).
- A deployment job: a special job type that records deployments to an environment and supports rollout strategies such as
runOnce,rollingandcanary. - The environment. Its approvals and checks run before this job starts (question 257).
Templates let many pipelines share stages, jobs or steps. With extends, a central template can define the required structure, such as mandatory security stages, and teams fill in only the parts it allows (question 260).
257. How do approval checks and environment permissions work in a managed CI/CD platform?
The short answer
They are attached to the environment, not written in the pipeline file, so they cannot be removed by editing the pipeline. When a job wants to deploy to a protected environment, the platform pauses it and runs the environment's checks: required approvers, wait timers, allowed branches, business hours, a passing monitoring query, or an outside change-management system. Only when all of them pass does the job start and receive the environment's secrets. Separately, permissions decide who may approve, who may deploy, and who may change the rules themselves.
The checks you typically find:
| Check | What it does |
|---|---|
| Required approvers | Named people or groups must approve, often not the author |
| Wait timer | A fixed delay, for example after a staging deploy |
| Branch control | Only main, or only release tags, may deploy |
| Business hours | Deploy only within a time window |
| Exclusive lock | One deployment at a time |
| Monitoring query | No active alerts on the service, for example from Azure Monitor |
| External system | A change ticket in a tool such as ServiceNow is approved |
Where each platform keeps them:
- GitHub Actions: environment protection rules, plus custom protection rules from apps (question 246).
- GitLab: protected environments and deployment approvals (question 254).
- Azure Pipelines: "approvals and checks" on environments and on other protected resources, such as service connections and variable groups.
Why "outside the pipeline file" matters. Anyone who can open a pull request can change the pipeline file. If the approval step lived only in that file, a pull request could delete it. Checks on the environment belong to the platform's settings, which only administrators can change.
Permissions to get right:
- Approvers are not the change's author, so one person cannot push and approve their own production change.
- Who may edit environments and their checks is a very small group.
- Every approval is recorded: who, when, and for which run, which is the audit trail regulated companies need (question 292).
Keep approvals meaningful. If approvers click "approve" without looking, the step adds delay but no safety. Give them a summary of what is being deployed, and automate the checks a person cannot do better than a machine (question 290).