Ask Your Question
0

How can reusable workflows receive input environmental variables?

asked 2023-06-03 06:17:01 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-03 06:23:01 +0000

qstack gravatar image

Reusable workflows in GitHub Actions can receive input environmental variables by defining input parameters in the workflow file. These input parameters can then be referenced and passed as arguments to reusable workflows.

Here's an example of how to define input parameters in a reusable workflow:

# in reusable-workflow.yml

name: My Reusable Workflow
on: push

inputs:
  my-variable:
    description: 'An example environmental variable input'
    required: true

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Print the input variable
        run: echo "I received the input variable: ${{ inputs.my-variable }}"

In this example, the reusable workflow takes one required input variable called my-variable. The variable is then referenced in a step that prints its value.

To use this reusable workflow with input variables, you can reference it in your main workflow file and pass the input variables like this:

# in main-workflow.yml

name: My Main Workflow
on: push

jobs:
  my-job:
    runs-on: ubuntu-latest
    steps:
      - name: Use the reusable workflow
        uses: my-org/my-repo/reusable-workflow@main
        with:
          my-variable: 'hello world'

In this example, the main workflow file references the reusable workflow and passes the my-variable input with the value 'hello world'.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-03 06:17:01 +0000

Seen: 2 times

Last updated: Jun 03 '23