I have a "Workflow B" that is automatically triggered when "Workflow A" is completed. Workflow A is triggered by each new Pull Request so the branch changes dynamically.
name: Workflow B
on:
workflow_run:
workflows: ['Workflow A']
types:
- completed
workflow_dispatch:
jobs:
first-workflow-job:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
cache: 'npm'
I would expect Workflow B to run on the same branch as Workflow A.
However, Workflow B runs on master.
How can I share the branch value between these workflows?
2
Answers
I have finally found the solution to my problem! Again, thanks to everyone who contributed so far.
So the solution relies on
workflow_run
context. The only addition we need is in Workflow_B where we access the trigger workflow's head branch:GitHub Actions does not seem to support directly sharing outputs between different workflow.
Workflows are designed to be self-contained, and while you can trigger one workflow after another using the
workflow_run
event, there’s no built-in method for passing data directly from one workflow to another.Workarounds, such as using artifacts or the repository itself to pass data, have certain restrictions and are often not reliable across separate workflows due to the concurrent nature of workflows.
You might consider
dawidd6/action-download-artifact
, an action that downloads and extracts uploaded artifacts associated with a given workflow and commit or other criteria.with workflow A: