1

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

3
  • Your script is writing to a file, not an environment variable. Also, env vars are only passed on to child processes, not to siblings or parents, in case that's what you assume. Commented Mar 16, 2022 at 14:23
  • Why use echo in the first place to set a env variable? Why not declare it right away? Im just currious, perhaps you have a good reason, but this seems needless. Commented Mar 16, 2022 at 14:26
  • If I understand GuiFalourd's answer correctly, it seems to be a configuration file actually. The "environment variable" in the question seems to be a red herring, at best the config file shows up as environment variables at some point. Commented Mar 16, 2022 at 14:55

1 Answer 1

3

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:

Sign up to request clarification or add additional context in comments.

1 Comment

just to add a follow-up. In my flow, I also used "cd" to the script location and then ran it. which I think is also related to my original issue. after removing the CD and doing @GuiFalourd recommendation I managed to get it working. Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.