Timeline for answer to How do I set an env var with a bash expression in GitHub Actions? by peterevans
Current License: CC BY-SA 4.0
Post Revisions
28 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 15, 2025 at 20:53 | comment | added | Elijah Lynn | Latest docs say: "You can make an environment variable available to any subsequent steps in a workflow job by defining or updating the environment variable and writing this to the GITHUB_ENV environment file. The step that creates or updates the environment variable does not have access to the new value, but all subsequent steps in a job will have access." | |
| Dec 4, 2024 at 9:40 | comment | added | Rafs |
Is env. prefix optional in run steps but mandatory in other steps?
|
|
| Oct 28, 2024 at 21:26 | comment | added | Bludwarf |
This solution is not allowed to set NODE_OPTIONS. Instead, you can try this workaround: github.com/orgs/community/discussions/…
|
|
| Jul 31, 2023 at 8:38 | comment | added | Tapa Dipti Sitaula |
Quick note: For this to work for me, I had to make some changes. What worked for me is adding quotes around $GITHUB_ENV when assigning the variable. That is, ... >> "$GITHUB_ENV". And I could only access the variable in a new step, not within the same step in which I assigned the variable. This is the GitHub docs page that I followed: docs.github.com/en/actions/using-workflows/…
|
|
| Apr 2, 2023 at 7:02 | comment | added | Fred | I just printed most of the variables, I couldn't post here because of the length limitation. You can check it out here (Print vars section): github.com/wxw-matt/test_release/actions/runs/4587386341/jobs/… | |
| Dec 31, 2022 at 1:11 | comment | added | lima_fil |
This doesn't answers the question. This works only in run part, but how to set the same in env for the step? This doesn't work: ``` env: GITHUB_SHA_SHORT: $GITHUB_SHA_SHORT GITHUB_SHA_SHORT: ${{ env.GITHUB_SHA_SHORT }} ```
|
|
| Sep 28, 2022 at 22:41 | comment | added | Redbeard | @honey_ramgarhia, I was wondering the same thing and found the answer here: stackoverflow.com/a/63485275/13040522 Basically you need to create a workflow env variable, set it in the echo statement and then output it from the job since they run on different virtual machines | |
| Dec 7, 2021 at 9:38 | comment | added | krlmlr |
tee -a is slightly more useful than >>: it shows the newly set environment variable in the output.
|
|
| Oct 20, 2021 at 17:20 | comment | added | Tim Kretschmer |
ruby script: db_url = "postgresql://#{user}:#{RDS_PASSWORD}@#{host}:#{port}/#{db_name}" this means, then i could set the ENV variable out of a ruby script and then re-use it in another script later in life DATABASE_URL='#{db_url}' >> $GITHUB_ENV
|
|
| May 28, 2021 at 15:50 | history | edited | Lee Meador | CC BY-SA 4.0 |
added 138 characters in body
|
| May 28, 2021 at 15:47 | comment | added | Lee Meador | I, too, got bitten by the curly braces in the quoted section. | |
| Mar 5, 2021 at 8:54 | history | edited | peterevans | CC BY-SA 4.0 |
deleted 4 characters in body
|
| Mar 5, 2021 at 4:46 | comment | added | honey_ramgarhia | But what about if I want to use this variable in multiple jobs? Is there any way to define a workflow level variable? | |
| Feb 19, 2021 at 21:14 | comment | added | IvanD | BEWARE of the fine print :) "The action that creates or updates the environment variable DOES NOT have access to the new value, but all subsequent actions in a job will have access." | |
| Nov 23, 2020 at 10:30 | comment | added | Carsten |
Just a quick note (since this caused me headache). If you are using a Windows/PowerShell environment, you have to use $env:GITHUB_ENV, i.e. something like run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $env:GITHUB_ENV.
|
|
| Oct 2, 2020 at 6:36 | history | edited | peterevans | CC BY-SA 4.0 |
Updated due to recent Actions runner changes
|
| Jul 10, 2020 at 8:41 | comment | added | Danielo515 |
echo ${{ env.GITHUB_SHA_SHORT }} I think that is not an alternative syntax, but it uses the Github template engine. That means that you can embed the env variable on places where you usually will not be able to, while $VARNAME is only available to shell environment
|
|
| Jun 20, 2020 at 9:12 | history | edited | Community Bot |
Commonmark migration
|
|
| Apr 28, 2020 at 23:14 | comment | added | peterevans |
@SudoPlz I think the only way is to duplicate the set-env command, yes. You can execute multiple set-env commands in the same run step, though.
|
|
| Apr 28, 2020 at 16:04 | comment | added | SudoPlz | what about setting multiple keys and values? Do we just duplicate that same command or is there a way to do it with 1 command? | |
| S Mar 29, 2020 at 21:54 | history | suggested | marengaz | CC BY-SA 4.0 |
updated link
|
| Mar 29, 2020 at 16:36 | review | Suggested edits | |||
| S Mar 29, 2020 at 21:54 | |||||
| Nov 4, 2019 at 2:32 | history | edited | peterevans | CC BY-SA 4.0 |
added 155 characters in body
|
| Sep 21, 2019 at 4:02 | comment | added | peterevans |
@evilSnobu Not sure if it fits your use case, but there is another similar method for passing values to later steps using set-output that I've detailed here. stackoverflow.com/questions/57819539/…
|
|
| Sep 17, 2019 at 9:22 | comment | added | evilSnobu | Removed the extra curly brackets (unnecessary as they become part of the value) and added link to doc. Thanks! | |
| Sep 17, 2019 at 9:21 | vote | accept | evilSnobu | ||
| Sep 17, 2019 at 9:21 | history | edited | evilSnobu | CC BY-SA 4.0 |
Added link to set-env doc
|
| Sep 17, 2019 at 7:43 | history | answered | peterevans | CC BY-SA 4.0 |