Skip to content

Update Reusable Workflows Documentation to Include Limitations on Environment Variables #39604

@0xMurage

Description

@0xMurage

Code of Conduct

What article on docs.github.com is affected?

https://github.com/github/docs/blob/fe2f56a5677b8d9451961c8789269dd2976793c2/content/actions/how-tos/reuse-automations/reuse-workflows.md

What changes are you suggesting?

Add a Limitations section to the reusable workflows documentation to clarify that reusable workflows do not currently support passing custom environment variables directly, except for default environment variables like github.head_ref .

Highlight a workaround using job outputs to pass dynamic values.

Additional information

Calling reusable workflows with a value like ${{ github.event.pull_request.number }} will not work as expected.

Example of What Does Not Work:

name: Call a reusable workflow

on:
  pull_request:
    branches:
      - main

jobs:
  call-workflow:
    uses: octo-org/example-repo/.github/workflows/workflow-A.yml@v1
    with:
       pr_number: ${{ github.event.pull_request.number }}

Workaround: Pass env values using a job output.

Example of Workaround:

name: Call a reusable workflow

on:
  pull_request:
    branches:
      - main

jobs:
  setup-env:
    runs-on: ubuntu-latest
    outputs:
      pr_num: ${{ steps.set-pr-number.outputs.pr_num }}
    steps:
      - name: Set pull request number
        id: set-pr-number
        run: |
          echo "pr_num=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT

  call-workflow:
    needs: setup-env
    uses: octo-org/example-repo/.github/workflows/workflow-A.yml@v1
    with:
      pr_number: ${{ needs.setup-env.outputs.pr_num }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    contentThis issue or pull request belongs to the Docs Content teamgithub_actionsPull requests that update GitHub Actions code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions