-
I have a common task that I need to perform for all job “variants” in a matrixed build. My idea was to use a separate job for that but I’m unsure how to pass a build output between two jobs. Before needing to do a matrixed build (where we build both versions in parallel), I had been doing this all as one job. My question now is, what is the best way to share information from one job (the newly incremented verison) with the matrixed job that depends on it? See below for some abberviated code. I haven’t tried to run it yet but I’m sure it will fail since AFAIK you can’t refernce steps from another job. I’m also aware of artifacts but we’re talking about a variable here and not some file. TIA
|
Beta Was this translation helpful? Give feedback.
Replies: 20 comments 11 replies
-
As jobs run in different runners, those runners are in different machines. Each job runs in a fresh instance of the virtual environment specified by runs-on. It is not possible to share environment variables between machines. We don’t support to share variables between jobs. Please refer to: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/persisting-workflow-data-using-artifacts |
Beta Was this translation helpful? Give feedback.
-
I hadn’t thought of writing the variable to a file but I guess that could work. Thanks for clarifying that it’s not possible to share information any other way. I do think this could be a feature worth adding at some point. Writing to a file seems like overkill for a single variable. Thanks again. |
Beta Was this translation helpful? Give feedback.
-
How to explain therefore that we can define environment variables at a global level as follows (thanks):
|
Beta Was this translation helpful? Give feedback.
-
Hi distinctlab, Yeah, you could set a workflow level environment variable, which could be used in all jobs. But the original poster needs set the env variable inside a job. Then the env could only be used in that job. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the tip. I found Github documentation provides how to share data between jobs.
|
Beta Was this translation helpful? Give feedback.
-
Thanks for your feedback. One of the current imits of github actions is to be able to declare from a job a global (workflow) |
Beta Was this translation helpful? Give feedback.
-
Yeah, you are right. Github Actions could not declare a global env in one job and use it in other jobs in a workflow. I would recommend you to share your idea in the Feedback form for GitHub Actions. |
Beta Was this translation helpful? Give feedback.
-
In the same way it’s possible to share variables between steps, it should be possible to share variables between jobs as well. Since a job can declare its dependence on another job, the dependee could easily have its ouput variables persisted and exposed to dependent jobs through an expansions of the existing steps.<step_id>.outputs.<output_name> syntax with jobs.<job_id>.steps.<step_id>.outputs.<output_name>. Example below:
|
Beta Was this translation helpful? Give feedback.
-
The new jobs.<jobs_id>.outputs syntax should support this.
|
Beta Was this translation helpful? Give feedback.
-
Thanks for heads up, @bradymholt, this is extremely helpful. And exactly what I needed. |
Beta Was this translation helpful? Give feedback.
-
Probably way too late, but I use this extension to share variables between jobs. GitHubShare Jobs Data - GitHub MarketplaceShare data between GitHub Actions jobs I use it to release my artifacts into one release, so to store the release URL, which I need in another job.
To get the value so I can use it again.
to access the data you do: ${{ steps.get_upload_url.outputs.data }}. |
Beta Was this translation helpful? Give feedback.
-
EDIT 2022/10 Due to deprecation of
|
Beta Was this translation helpful? Give feedback.
-
@ dimisjim response should be the solution. Please change it just in case someone doesn’t scroll down enough! |
Beta Was this translation helpful? Give feedback.
-
@MostefaKamalLala I flagged the current solution and got the staff to change the solution. 👏t2: |
Beta Was this translation helpful? Give feedback.
-
Agreed, it’s a shame there is not a more flexible solution for sharing data between jobs, as even the parameters option has so many limitations (ran in to another one today) In short:
Here’s hoping for more improvement in this area. |
Beta Was this translation helpful? Give feedback.
-
I tried similar but not working for me.
It is failing as value not detected.
|
Beta Was this translation helpful? Give feedback.
-
ukreddy-erwin:
There’s no output called |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, using output is deprecated. It's being replaced by Environment Files. However, it doesn't look like it supports sharing env between jobs. Only sharing env between steps is supported right now. So it seems like we're back to square one again.
|
Beta Was this translation helpful? Give feedback.
-
Does this work in a matrix job? If I have a matrix the steps are the same, but run with different configurations. How does that appear if the output is "flat"? |
Beta Was this translation helpful? Give feedback.
-
I couldn't get this to work if the job that you want to output is ran with For example:
Here is an example of the main file:
This is the file that delcares the steps in
|
Beta Was this translation helpful? Give feedback.
EDIT 2022/10
Due to deprecation of
set-output
the reccomended approach is now: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter