# CI/CD Cheat Sheet

Course: [CI/CD](https://www.devtutorials.ai/learn/cicd) · Section: Reference
Source: https://www.devtutorials.ai/learn/cicd/reference/cheat-sheet

> Every task from the course side by side for GitHub Actions, Azure Pipelines and GitLab CI, with the lesson that owns each idea.

## CI/CD Cheat Sheet

The same task on each platform. Each row links back to the lesson that owns the idea.

**Simple lesson:** find the task in the left column, copy the line for your platform.

## Triggers

| Task | GitHub Actions | Azure Pipelines | GitLab CI |
|---|---|---|---|
| Run on push to main | `on: push: branches: [main]` | `trigger: branches: include: [main]` | `rules: - if: $CI_COMMIT_BRANCH == "main"` |
| Run on pull requests | `on: pull_request` | `pr: branches: include: ['*']` | `rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event"` |
| Run at 2 AM UTC | `schedule: - cron: '0 2 * * *'` | `schedules: - cron: '0 2 * * *'` | A pipeline schedule in project settings |
| Run by hand | `workflow_dispatch:` | Always on | `when: manual` |

Owner: Your First Pipeline.

## Jobs and Steps

| Task | GitHub Actions | Azure Pipelines | GitLab CI |
|---|---|---|---|
| Pick the machine | `runs-on: ubuntu-latest` | `pool: vmImage: ubuntu-latest` | `image: node:22` |
| Run a command | `run: npm test` | `script: npm test` | `script: - npm test` |
| Wait for a job | `needs: build` | `dependsOn: build` | `needs: [build]` |
| Time limit | `timeout-minutes: 15` | `timeoutInMinutes: 15` | `timeout: 15m` |
| Set a value | `env: API_URL: …` | `variables: API_URL: …` | `variables: API_URL: …` |
| Matrix | `strategy: matrix: node-version: [20, 22]` | `strategy: matrix: node20: …` | `parallel: matrix: - NODE: ["20", "22"]` |

Owners: Your First Pipeline, Reading Red Builds, Faster Pipelines.

## Speed

| Task | GitHub Actions | Azure Pipelines |
|---|---|---|
| Cache npm | `actions/setup-node` with `cache: npm` | `Cache@2` with key from `package-lock.json` |
| Cache NuGet | `actions/setup-dotnet` with `cache: true` | `Cache@2` with key from `packages.lock.json` |
| Cancel old runs | `concurrency:` + `cancel-in-progress: true` | `pr: autoCancel: true` |

Owner: Faster Pipelines.

## Artifacts

| Task | GitHub Actions | Azure Pipelines |
|---|---|---|
| Save output | `actions/upload-artifact` | `PublishPipelineArtifact@1` |
| Get output | `actions/download-artifact` | `DownloadPipelineArtifact@2` (automatic in deployment jobs) |
| Commit SHA | `${{ github.sha }}` | `$(Build.SourceVersion)` |
| Build number | `${{ github.run_number }}` | `$(Build.BuildNumber)` |

Owner: Artifacts and Versions.

## Tests and Workflow Logic

| Task | GitHub Actions | Azure Pipelines |
|---|---|---|
| Publish a test report | `dorny/test-reporter` | `PublishTestResults@2` |
| Run after a failure too | `if: ${{ !cancelled() }}` | `condition: succeededOrFailed()` |
| Database for tests | `services: postgres: image: postgres:17` | `resources: containers:` + `services:` |
| Pass a value to a job | `>> "$GITHUB_OUTPUT"` + `needs.<job>.outputs.<name>` | `##vso[task.setvariable …;isOutput=true]` + `dependencies.<job>.outputs['<step>.<name>']` |
| Skip docs-only changes | `paths-ignore: ['**.md']` | `trigger: paths: exclude: ['*.md']` |

Owner: Tests and Workflow Logic.

## Containers

| Task | GitHub Actions | Azure Pipelines |
|---|---|---|
| Sign in to the registry | `docker/login-action` with `GITHUB_TOKEN` | Docker Registry service connection |
| Build and push | `docker/build-push-action` with `push: true` | `Docker@2` with `command: buildAndPush` |
| Tag with the commit | `tags: ghcr.io/shop/shop-web:${{ github.sha }}` | `tags: $(Build.SourceVersion)` |
| Cache layers | `cache-from: type=gha`, `cache-to: type=gha,mode=max` | Use a registry cache image |
| Scan with a gate | `trivy image --exit-code 1 --severity CRITICAL,HIGH …` | Same command in a `script:` |
| Attest | `actions/attest-build-provenance` + `attestations: write` | Not built in |

Owner: Containers in CI.

## Security

| Task | GitHub Actions | Azure Pipelines |
|---|---|---|
| Pin outside code | `uses: owner/action@<40-char SHA> # v1.2.3` | Pin template repos with `ref:` |
| Read-only token | `permissions: contents: read` | Limit job authorization scope |
| Fork safety | `pull_request`, not `pull_request_target` | Keep fork secrets off (default) |
| No token on disk | `persist-credentials: false` | `persistCredentials` off (default) |

Owner: Pipeline Security.

## Delivery

| Task | GitHub Actions | Azure Pipelines |
|---|---|---|
| Use an environment | `environment: production` | `deployment:` job with `environment: production` |
| OIDC sign-in | `azure/login` + `id-token: write` | A workload identity service connection |
| Deploy an image | `azure/webapps-deploy` with `images:` | `AzureWebAppContainer@1` with `containers:` |
| Deploy a package | `azure/webapps-deploy` with `package:` | `AzureWebApp@1` with `package:` |
| Production on a release | `on: release: types: [published]` | `trigger: tags: include: ['v*']` |
| Roll back | deploy `${{ vars.LAST_GOOD_TAG }}` | deploy `$(LAST_GOOD_TAG)` |
| Main only | `if: github.ref == 'refs/heads/main'` | `condition: … eq(variables['Build.SourceBranch'], 'refs/heads/main')` |
| Run on failure | `if: failure()` | `condition: failed()` |
| Smoke test | `run: curl --fail --retry 5 … /health` | `script: curl --fail --retry 5 … /health` |
| Shared template | `uses: ./.github/workflows/x.yml` | `- template: templates/x.yml` |

Owners: Environments and Secrets, Deploy for Real, Deploy and Smoke Test, Rollback and Recovery, Pipelines as a Product.

## After the Deploy

| Task | GitHub Actions | Azure Pipelines |
|---|---|---|
| Message on failure | `slackapi/slack-github-action` + `if: failure()` | `curl` to the webhook + `condition: failed()` |
| Link to the run | `${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}` | `$(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)` |
| Debug logs | `ACTIONS_STEP_DEBUG: true` | `system.debug: true` |
| Windows too | `matrix: os: [ubuntu-latest, windows-latest]` | `matrix:` with `vmImage: $(imageName)` |

Owner: After the Deploy.

**Gitea Actions** reads GitHub Actions workflow files, with a few differences. Most of the GitHub column works there too. Check Gitea's documentation for the parts it does not support.

Next: **Pipeline Error Messages**
