Search code examples
githubcontinuous-integrationgithub-actionsworkflow

Environments in GitHub Actions incompatible with reusable workflows?


I have the following job

  build-and-push-docker-image:
    name: Build and push docker image
    if: github.repository == 'Org/repo'
    uses: Org/repo/.github/workflows/reusable.yaml@main
    with:
      dockerfile: My_Dockerfile
    environment:
      name: Production
    needs:
      - job-1
      - job-2
    secrets:
      SECRET_1: ${{ secrets.SECRET_1 }}

This fails the basic syntax checking as follows:

The workflow is not valid. .github/workflows/my_workflow.yml (Line: 236, Col: 5): Unexpected value 'environment'

Why is that?


Solution

  • According to the documentation, it is not possible to use environment with a reusable workflow. You would have to define it within the reusable workflow.

    See here: Supported keywords for jobs that call a reusable workflow