-
Hi, How can I pass environment variables to an input ?
|
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 2 replies
-
As explained by @cognitiaclaeves, not being able to reference global env:
DOCKER_RESOURCES: ./model/src/test/resources/docker
jobs:
build-jdk:
uses: ./.github/workflows/run-build-jdk.yml
with:
DOCKER_RESOURCES: ./model/src/test/resources/docker At worst then you have to run a new container to define a reusable ouput: env:
DOCKER_RESOURCES: ./model/src/test/resources/docker
jobs:
set-global-env-var:
runs-on: ubuntu-latest
steps:
- id: set-vars
env:
DOCKER_RESOURCES: ${{ env.DOCKER_RESOURCES }}
run: echo "DOCKER_RESOURCES=${DOCKER_RESOURCES}" >> $GITHUB_OUTPUT
outputs:
DOCKER_RESOURCES: ${{ steps.set-vars.outputs.DOCKER_RESOURCES }}
build-jdk11:
needs: set-global-env-var
uses: ./.github/workflows/build-jdk11.yml
with:
DOCKER_RESOURCES: ${{ needs.set-global-env-var.outputs.DOCKER_RESOURCES }} Hoping there's a feature in the pipe at GH to make it cleaner. |
Beta Was this translation helpful? Give feedback.
-
I think this question can be interpreted in multiple ways. I found this question while looking for a way to reuse global environment variables, preferably in a consistent way, regardless of if it was done in actions, composite actions, workflows, or reusable workflows. TLDR; - After defining global env vars, make them a job output through the special ... which is not needed when using env directly, but which can only be done for actions, and not reusable workflows. For the sake of this explanation, here are two example code-snippets: Here is the main workflow:
Here is a test reusable workflow:
I have three goals in taking the time to write this up:
As I was writing this, I finally figured out what @konradpabjan 's solution is demonstrating -- that you can use environment variables at the job level, rather than at every stage level. My examples do not include this, and I consider it outside of the scope of my purpose -- and since I now know that my mileage may vary significantly between reusable workflows, workflows and actions, I won't be doing the testing to determine if the job-level env variable works for reusable workflows. I would strongly suspect that it doesn't, but I leave this determination as an exercise for a consumer of this content. |
Beta Was this translation helpful? Give feedback.
-
Might need to update this answer now that |
Beta Was this translation helpful? Give feedback.
-
this is the best solution. Thanks @konradpabjan |
Beta Was this translation helpful? Give feedback.
-
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
|
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
I can use global variables as input like this for example:
So this is now implemented. |
Beta Was this translation helpful? Give feedback.
-
Btw is it going to be implemented with something like ${{ job.env.NAME }} maybe ? |
Beta Was this translation helpful? Give feedback.
-
Ok it works thanks. But small typo in your solution:
should be:
|
Beta Was this translation helpful? Give feedback.
-
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.
|
Beta Was this translation helpful? Give feedback.
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.
https://help.github.com/en/articles/development-tools-for-github-actions#set-an-output-parameter-set-output