Hi,
How can I pass environment variables to an input ?
- run: echo "##[set-env name=NAME;]CrazyMax"
- uses: actions/hello-world-javascript-action@master
with:
who-to-greet: $NAME
Hi,
How can I pass environment variables to an input ?
- run: echo "##[set-env name=NAME;]CrazyMax"
- uses: actions/hello-world-javascript-action@master
with:
who-to-greet: $NAME
You currently can’t reference environment variables as inputs. Unless you really want that particular value to be an environment variable I would suggest you set it as an output of the step and then you can reference that output in the input of subsiquent step.
- run: echo ::set-output name=action_fruit::strawberry
id: fruit
- uses: actions/hello-world-javascript-action@master
with:
who-to-greet: ${{ steps.fruit.outputs.action_fruit }}
Ok it works thanks. But small typo in your solution:
${{ steps.fruit.output.action_fruit }}
should be:
${{ steps.fruit.outputs.action_fruit }}
Btw is it going to be implemented with something like ${{ job.env.NAME }} maybe ?
I can use global variables as input like this for example:
env:
FOO: “bar”
job:
step:
env:
BAR: ${{ env.FOO }}
So this is now implemented.
Isn’t this transform-env-to-output just an ugly workaround? I want to reference things like GITHUB_WORKSPACE in my input parameters without workarounds or hacks.
You can now do something like this for passing in env variables.
Be aware, that env is just one of many contexts that you can use for passing in input
If you want to pass in certain types of information in such as the workspace, you should use the github context
jobs:
example:
runs-on: [ubuntu-latest]
env:
input: environment variable
steps:
# use env variable as input
- uses: actions/hello-world-javascript-action@master
with:
who-to-greet: ${{ env.input }}
# use input from the github context[https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context](https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context) - uses: actions/hello-world-javascript-action@master
with:
who-to-greet: ${{ github.repository}}
- uses: actions/hello-world-javascript-action@master
with:
who-to-greet: ${{ github.ref }}