Bootstrap FreeKB - GitHub Actions - Pass input between workflows
GitHub Actions - Pass input between workflows

Updated:   |  GitHub Actions articles

Let's say you have a reusable workflow, where a workflow in one of you repositories (the caller workflow) will use a workflow in one of your other repositories (the called workflow, also known as the reusable workflow). Check out my article Sharing Jobs using workflow_call and a private repository (reusable code).

This also assumes you are familiar with Output. If not, check out my article GitHub Actions - Getting Started with Output.

You can

The caller workflow can use the with keyword to define input variables that will be passed to the called workflow. In this example, the input variable "greeting" will be passed to the reusable workflow.

name: GitHub Action (POC)
run-name: ${{ github.workflow }} run by ${{ github.actor }}
on:
  workflow_dispatch:
jobs:  
  demo:
    uses: JohnDoe/Actions/.github/workflows/main.yml@main
  with:
    greeting: "Hello World"

 

And then the called workflow (the reusable workflow) would have on: workflow_call: inputs to pull in the inputs from the caller workflow and then the input can be used elsewhere in the called workflow. In this example, the "greeting" input variable is used.

name: Reusable Workflow
run-name: ${{ github.workflow }} run by ${{ github.actor }}
on:
on:
  workflow_call:
    inputs:
      container_name:
        type: string
        required: true  
  workflow_dispatch:
jobs:
  github-action-job:
    runs-on: ubuntu-latest
    steps:      
      - name: greeting
        run: echo ${{ inputs.greeting}}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 4ab4cf in the box below so that we can be sure you are a human.