-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to define env variable? #68
Comments
Hi @pascalandy! Take a look here for setting env vars: https://help.github.com/en/articles/virtual-environments-for-github-actions#environment-variables |
Hello @mscoutermarsh, thanks for replying. OK the big glitch I see in the fact that we need to redefine VAR at each steps:
this is how it looks when reusing VAR at each steps
I think this defeats the point of using VAR isn't? Maybe an .env file?Is there a way to define VARs via a |
regarding the doc
It's confusing that the docs you send me is not part of: https://help.github.com/en/categories/automating-your-workflow-with-github-actions So:
|
my goalAt the end, this is how I want to generate VARs for my docker tags:
|
solution1/ Here is a great hack to use on your @github actions. The pain is that when you set variables in a step in your workflow, further steps can NOT see the VAR 🙊. Officially you have to re-set VAR at each step. This sucks. Hold my beer 🍺 2/ Well, that sucked for about a day. Then I had 🙌🙌. I found a way to hack this limitation. Write your VAR on disk (the CI system disk), then |
|
@kangwonlee That would make the logs a pain to read :-p
|
@pascalandy Thanks for your opinion. What about adding a few
|
|
Yeah, I am beginning to realize that this (job-wide or workflow-wide env vars) is one of several things that GH Actions is missing. I love the idea of the yml-defined workflow, and it all inside GitHub, but it looks like these use common use cases aren't properly addressed (quite yet, I can hope). I had the same issue with conditions: setting conditions on a job. I can set it on a workflow, or a step, but not a job. Hmm, I should open an issue for this. In any case, looking forward to seeing broader env vars. |
@deitch it is not missing anymore, it is now alive https://github.blog/changelog/2019-10-01-github-actions-new-workflow-syntax-features/#env-at-the-workflow-and-job-level |
Oh good. One piece answered... |
Hi, I'm trying something similar. I will upload a folder to AWS S3, but its not working. First i run the command of configure the secrets and after the command of publish. My job:
So, the output is: So the upload failed. It seens can't get the envs. I tried in others ways, but didn't work either. Someone have some idea? |
I created a |
Thank you @pascalandy, but we'd like to keep issues related to code in this repository. It looks like with https://github.blog/changelog/2019-10-01-github-actions-new-workflow-syntax-features/#env-at-the-workflow-and-job-level you've got what you need. @pascalandy, @richardbertozzo and others:
Thanks all. |
I get that you guys made a "Github Actions" specific way of using ENV_VAR. I feel my solution is more agnostic. Anyways, I'll respect your point of view on this. Cheers! |
Can I not used env vars in with?
This fails!
This fails too... And based in the error message it seems the artifact path needs to be relative ... |
I found en even easier way buried somewhere in the docs is this syntax: ::set-env name={name}::{value} This is how you use it: echo "::set-env name=APP_NAME::$(cat Dockerfile | grep APP_NAME= | head -n 1 | grep -o '".*"' | sed 's/"//g')" I know it's weird with the EDIT:The above actually works not just in bash with the print("::set-env name=APP_NAME::{}".format("foo")) |
@smac89 it doesn't seem set-env work across jobs, seems only valid for the following steps in the same job. I wonder if there is any way to pass such env var across jobs. My use case is building an RN app, one job on ubuntu and one job on osx, they need to share some vars like tag_name, build_number and such var could be based on datetime for example. |
Hmm, why this request was closed? https://github.blog/changelog/2019-10-01-github-actions-new-workflow-syntax-features/#env-at-the-workflow-and-job-level says that env variable can be set at workflow or job level, but it's not true: it can be set at job or step level only (or at least only these are documented). |
The solution with the echo "::" is not bad. You could wrap it in an action to make it even nicer to use. |
Hello 👋 I have reached here trying to solve the same thing 😄 I have been able to workaround it looping the file and setting the env vars with the - name: Set ENV variables
run: for v in `cat env` ; do echo "::set-env name=${v%%=*}::${v##*=}" ; done
NOTE: if the above one-liner grabs your attention, this post explains how key/values are extracted. |
This works perfectly for me 💯 👌
After you can use ${{steps.date.outputs.date}} to use a value. |
You can set environment variables by saving it in ~/.bashrc or ~/.bash_profile in one step and by using source command you can export vars in other steps.
|
On the contrary I find the feedbacks very useful since the thread makes look like the problem has been solved but it's not. |
* For each step in a job, the env is reset. The only thing that is persistent is files. * Buried in the docs at https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable * Also debug that this has been done just before test stage * NB: You can capture the entire env with this one-liner: run: for v in `cat env` ; do echo "::set-env name=${v%%=*}::${v##*=}" ; done via:actions/starter-workflows#68 (comment)
* For each step in a job, the env is reset. The only thing that is persistent is files. * Buried in the docs at https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable * Also debug that this has been done just before test stage * NB: You can capture the entire env with this one-liner: run: for v in `cat env` ; do echo "::set-env name=${v%%=*}::${v##*=}" ; done via:actions/starter-workflows#68 (comment)
I don't understand how that would look with syntax. It'd be nice if they actually showed an example |
I'd just like to see a new category for secrets that isn't hidden and one way - a not so secret option to set arbitrary env vars, and see/edit their values and they get applied like secrets to every build. every other CI server out there does this, why not actions?? |
Sorry, but we'd like to keep issues related to code in this repository. Thank you 🙇 If you have questions about writing workflows or action files, then please visit the GitHub Community Forum's Actions Board If you are having an issue or question about GitHub Actions then please contact customer support |
I understand this is an old issue, but as I couldn't quickly find reference to the official documentation on Environment Files, this may help clarifying the latest on this. With the new setup, rather than using jobs:
date:
runs-on: ubuntu-latest
steps:
- name: Get date
run: |
echo "current_date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Echo env date
run: |
echo "${{ env.current_date }}" Also, as mentioned in the doc, you can have more complex multiline setup. jobs:
curl:
runs-on: ubuntu-latest
steps:
- name: Get teapot
run: |
echo 'teapot<<EOF' >> $GITHUB_ENV
curl https://httpbin.org/status/418 >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Echo env teapot
run: |
echo << 'EOF'
${{ env.teapot }}
echo 'EOF' |
Why is this so damn complicated? The internet is full of contradictory examples and workarounds that are probably out of date. The worst thing is that there are github DOCS containing both the, in theory duplicated, way and the new way. Why all this syntax weirdos and hacky things? Why not stick to the same syntax as the rest of the stuff? Is it really that hard to allow:
And maybe add a flag to decide if it should be set globally or not. C'mon, everytime I have to configure a workflow I spend more time looking for the right way of doing things than the time they will be running. |
@danielo515 Your suggestion seems half-baked. Adding a flag is not going to make things more clear. |
@eyal0 it uses the same syntax as the rest of the steps. It seems intuitive to me. The only reason why I proposed a flag is because there is already an env directive. Maybe use a different name, like set-envs, but the current solution is not intuitive nor properly documented and does not work consistently across runners (windows machines for example) |
Defining env vars is a different way actions/starter-workflows#68 (comment)
Defining env vars is a different way actions/starter-workflows#68 (comment)
Defining env vars is a different way actions/starter-workflows#68 (comment)
It took me a while to figure it out, but I got it working like this: jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Setup
run: sudo apt update && sudo apt install -y jq
- name: Name Generator
run: |
echo 'RANDOM_NAME='$(curl https://randomuser.me/api | jq '.results[0].name.first') >> $GITHUB_ENV
- name: Display Name
run: |
echo ${{ env.RANDOM_NAME }} |
Just coming here to post this current answer because there is a lot of outdated methods here. To set an run: echo "name=value" >> $GITHUB_ENV Latest docs can be found here. Using |
Hi,
I worked for few hours around the CI aspect of Github actions and the big piece that is missing is about how to define variables.
my yml
what I want to do
Of course, the tag
devmtl/rclone:2.29.1-2019-08-24-32c812f7
should be dynamic. I need to:From there, I should be able to generate all the tags required.
See how I do this using Travis:
https://github.com/firepress-org/ghostfire/blob/master/.travis.yml#L45
Cheers!
The text was updated successfully, but these errors were encountered: