'How can I access environment variable set in external bash script in Github Actions?

I try to add a Jira ticket validation for our repository and decided to do it with Github actions.

I have an external bash script that I run in one step which sets the result if a Jira ticket is found to an environment variable.

I have another step which tried to access this environment variable and fail/success the flow by the result.

However, I can't seem to make it work, I don't see the new environment variable configured in the bash script.

Some code:

script.sh:

...
echo "jira_ticket_exists=false" >> "$GITHUB_ENV"
...

Github action step:

    - name: choose to reject or not
    id: jira_ticket_reject
    continue-on-error: true
    run: |
      env # searched for it also here - it doesn't exist.
      echo ${{ env.jira_ticket_exists }} # this returns nothing
      if [ ${{ env.jira_ticket_exists }} == "true" ]; then
        echo "Jira ticket found"
        exit 0
      else
        echo "Jira ticket not found"
        exit 1
      fi

Any ideas what I'm doing wrong?

thank you



Solution 1:[1]

I tested the same thing here and the problem seems related to the double quotes you used with the $GITHUB_ENV.

In your shell script, instead of:

echo "jira_ticket_exists=false" >> "$GITHUB_ENV"

You should use:

echo "jira_ticket_exists=false" >> $GITHUB_ENV


Here is the demo I used if you want to check:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GuiFalourd