Friday, October 28, 2022

[SOLVED] How to pass the output of a bash command to Github Action parameter

Issue

I have a workflow where after a push to master I want to create a release and upload an asset to it.
I'm using actions/create-release@v1 and actions/upload-release-asset@v1.

I would like to pass the outputs of a bash commands to the action parameters. However I found out the syntax of "$(command)" does not work.

How can I pass the output of a bash command to an action's parameter.

For example I'd like to do something like this:

- name: Create Release
  id: create_release
  uses: actions/create-release@v1
  env:
    GITHUB_TOKEN: ${{ secrets.token }}
  with:
    tag_name: $(cat projectFile | grep -Po '(?<=Version>).*(?=</Version>)')

Solution

UPDATE: This answer will not work as GitHub as disabled this syntax for security reasons. You should use environment files instead.

I would create an environment variable based of your command output:

- name: Retrieve version
  run: |
    echo ::set-env name=TAG_NAME::$(cat projectFile | grep -Po '(?<=Version>).*(?=</Version>)')

And then access it like the following:

- name: Create Release
  id: create_release
  uses: actions/create-release@v1
  env:
    GITHUB_TOKEN: ${{ secrets.token }}
  with:
    tag_name: ${{ env.TAG_NAME }}


Answered By - SolalVall
Answer Checked By - David Goodson (WPSolving Volunteer)