Github Action Branch "feature" is not allowed to deploy to dev due to environment protection rules

Viewed 403

I have setup one Github Action workflow. In which I want to trigger job when Pull request is merged from feature to dev branch. I have use Github Action environment with one protection Rule. Github Action is throwing an error message Branch "feature" is not allowed to deploy to dev due to environment protection rules.

Attaching .yaml of workflow.

name: "terraform-deploy"
on:
 pull_request:
   types:
     - closed
   branches:
     - dev
jobs:
  dev-plan:
    if: github.event.pull_request.merged
    environment:
      name: dev
    runs-on: ubuntu-20.04
    steps:
     - name: "my task"
       run: echo "hello"

enter image description here

1 Answers

By using the trigger

on:
  pull_request:
    types: [closed]

You're running the workflow on the source branch (e.g. feature/xyz) once the pull request has been closed (and merged in your case, because you included another condition in the job).

Since you want to run this job on the dev branch, I suggest changing your condition to:

on:
  push:
    branches: [dev]

and remove the condition if: github.event.pull_request.merged.

With these changes, your workflow is going to be run on any push to dev, which includes pull request merges as well as direct pushes.

Related