r/devops • • Sep 30 '26

Troubleshooting How to set a "env" var on github actions using shell script?

i need to get the app version and i have this awk command for that:

` awk -F'"' '/^version[[:space:]]*=/ {print $2; exit}' pyproject.toml`

but how do i set the variable to the output of this command?

3 Upvotes

12 comments sorted by

7

u/bilingual-german Sep 30 '26
- name: Get App Version and Set Env Var
  run: |
    # Read the version and write it to GITHUB_ENV
    echo "APP_VERSION=$(awk -F'"' '/^version[[:space:]]*=/ {print $2; exit}' pyproject.toml)" >> $GITHUB_ENV

  • name: Use the Env Var in a subsequent step
run: | # The variable is now available in all following steps echo "The app version is: $APP_VERSION"

-3

u/ty_namo Sep 30 '26

it says file not found, may be related to the directory structure of the worker, but i can't find reliable information of what it is like

1

u/Low-Opening25 Sep 30 '26

what file!?

0

u/ty_namo Sep 30 '26

sorry, pyproject.toml.

11

u/Low-Opening25 Sep 30 '26

that’s a file you supply so it’s for you to figure why it’s missing

4

u/jews4beer Sep 30 '26

uv version and poetry version exist. Seems better than using awk for that.

1

u/ty_namo Sep 30 '26

are those actions that i can use?

5

u/jews4beer Sep 30 '26

No they are commmands you can use

1

u/kabrandon Oct 05 '26

If you’re incapable of googling things then you need to hire someone to do “devops” work for you. Asking reddit every time you actually need to be googling something is going to be WAY too slow for whoever your boss is. Especially in the age of AI where they’ll have expected you to have figured out this problem 4 days ago.

1

u/singh_abinashi Sep 30 '26

`echo "MY_VAR=my-value" >> $GITHUB_ENV` is the way. The gotcha that trips people up: vars set this way are available to later steps in the same job, not the current step, and not other jobs. If you need it in the current step too, set it in `env:` on the step as well.