How do you protect production deploy jobs in GitHub Actions or GitLab CI?
IntermediateProductionTesting, CI/CD and Quality
Answer
- Put the prod job behind a protected environment with required reviewers (GitHub) or a
when: manualjob on a protected branch with protected environment approvals (GitLab). - Only the prod environment holds prod secrets or can assume the prod OIDC role.
- Require the same commit to have passed lint, Molecule and the staging deploy first (
needs:chains). - Show the
--check --diffoutput for prod in the approval step so the approver sees what will change. - Use
concurrency(GitHub) orresource_group(GitLab) so two prod runs never overlap.
deploy-prod:
needs: [deploy-staging]
environment: production
concurrency: ansible-prod
The goal is that nobody, including admins, can push to main and have it reach prod unreviewed.
More on Testing, CI/CD and Quality
What does a testing pyramid look like for Ansible code?BeginnerHow do you roll out `ansible-lint` profiles across a team without blocking everyone?IntermediateWhen do you use `skip_list`, `warn_list` and `# noqa`?IntermediateHow do you set up pre-commit hooks for an Ansible repo?BeginnerHow is a Molecule scenario laid out, and what does `molecule test` actually run?IntermediateDocker, Podman or real VMs as the Molecule driver: how do you choose?Advanced