In every CI solutions, it's possible to pause a pipeline and wait to a manual approval to continue (Jenkins, CircleCI, GitlabCI).
How to do this with Github Actions ?
Afaik there is no manual triggering at the moment. You can only re-run failed workflows.
But there are lots of useful events to achieve similar things.
Ex.: the Label event: Someone puts the "Approved" label on a PR.
Or the Pull request review comment event: Someone comments "Deploy to stage." on a PR.
Seems you can do this now using Environments: https://devblogs.microsoft.com/devops/i-need-manual-approvers-for-github-actions-and-i-got-them-now/
Simply create an environment, select required reviewers, add yourself or a team, and then hit save.
Then associate the environment in your Github Actions YAML file like so
environment:
name: <Your Github Environment here>
Then to release that step you can click "Review Deployments" and then choose which environment you want to deploy.
There is a way to do it now (not sure when this started being available, but I just saw it). So basically just add "workflow_dispatch:" before your workflow like this
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
And now when you navigate to "Actions" tab and select the workflow you added this command to, you see a "Run workflow" dropdown above the list. Use this control to manually run your workflow.
Here is where you should see the button.
I have to work with GitHub Actions for my current work, I can't say I'm amazed on how they evolved this product with the Microsoft wallet backing them.
Anyway, there is still no dedicated feature to do that very simple and needed task. I got a not so bad and not so dirty workaround though.
If you are not using environments just define one, call it "manual_approval" or something similar and assign required approver (can be groups). That will do the trick.
If you are already using Environments (and you should). Just define 2 Environment entries for each (ie. "prod" & "prod-manual"). Then configure then the same way just adding the required approver on the manual one.
You now just have to add this environment in your pipeline as in this example:
name: manual approval demo
on:
push:
jobs:
tf_plan:
name: Terraform Plan
runs-on: terraform
environment: Prod
steps:
...
tf_apply:
name: Terraform Apply
runs-on: terraform
environment: Prod-manual
steps:
...
You have to define 2 environments per real life environment as the workflow can reference only a single environment per job.
That's not perfect, but once again that's the less ugly I came up with. GitHub Actions is really lacking maturity compared to other tools.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With