28

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 ?

Antoine
  • 4,456
  • 4
  • 44
  • 51
  • Possible workaround: trigger a run via a comment maybe? https://github.community/t/trigger-a-github-workflow-if-it-matches-a-particular-comment-in-the-pull-request/116402 – Ben Creasy Sep 26 '21 at 04:08

6 Answers6

10

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/ or the documentation: https://docs.github.com/en/actions/managing-workflow-runs/reviewing-deployments

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.

Antoine
  • 4,456
  • 4
  • 44
  • 51
Matt Dell
  • 9,205
  • 11
  • 41
  • 58
7

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.

  • For others finding this: the documentation: https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#using-environments-to-manually-trigger-workflow-jobs – winkbrace Dec 29 '22 at 11:47
5

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.

scthi
  • 2,205
  • 1
  • 18
  • 14
4

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.

markovic-m
  • 161
  • 1
  • 1
  • 7
  • 1
    That's not exactly my question, yes it's possible to trigger a pipeline(or a job) but not a single step. – Antoine Oct 06 '21 at 12:19
  • 1
    @Antoine my bad.... This popped when i was looking for "how to manually trigger..", so I overlooked – markovic-m Oct 06 '21 at 15:41
3

You could make a simple step in your workflow, that does nothing but echo something - and set an environment on that step with required reviewers.

Like here, where I have made a "ManualApprove" step that is required to succeed before my Plan step runs through. The "approvers" environment contains nothing but the required reviewers.

ManualApprove:
needs: TerraformShow
environment:
  name: approvers
runs-on: ubuntu-latest
steps:
- name: manual approve
  run: |
      echo "Manually approved"

Workflow

This will give you a button you can click, like you know it from GitLab etc...

asguldbrandsen
  • 163
  • 1
  • 2
  • 13
1

There is no manual trigger at the moment, however, Github provides on_dispatch event which you can target to initiate a re-run. You can do this via curl or also from within Postman. I have written up a solution with Postman and included screenshots here: https://medium.com/@christinavhastenrath/how-to-run-github-actions-manually-afebbe77d325

Github also just released their GitHub Actions API, which can be used to build triggers. You can find the API docs here: https://developer.github.com/v3/actions/

GitHub officials response is that they are thinking about a non-conditional re-run of an action but nothing confirmed yet. You can follow the conversation in the Github community here on any updates: https://github.community/t5/How-to-use-Git-and-GitHub/Is-it-possible-to-manually-force-an-action-workflow-to-be-re-run/td-p/25336

C-Dev
  • 425
  • 1
  • 6
  • 15