use env variable in strategy matrix #56787
Replies: 6 comments 7 replies
-
|
You can't, the
A job output would work there. Small catch: The value of an output is a string. If you want to define an array from it, that string must be valid JSON defining the array. Then use |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the reply.
But then again what's the use if I have to repeat the code instead of defining it at one place(that I thought would be environment variables) and moreover the string which I want to mention will not be generated as an output, that will more like user-defined value.
Is there any other way in which I can achieve it, that is, just mention that string(may we can convert it to json later-on in your code, like you suggested) once in the code and use it in strategy matrix?
2 questions:
Can I convert the string value of an env variable to json like you showed and use it in strategy tag?
You said we can use env variable anywhere except id and uses keys, why can't we use it in strategy tag?
Thanks,
Shreyans Bhardwaj
Linux System Administrator
From: Airtower ***@***.***>
Sent: Wednesday, May 31, 2023 1:07 AM
To: community/community ***@***.***>
Cc: Shreyans Bhardwaj ***@***.***>; Author ***@***.***>
Subject: Re: [community/community] use env variable in strategy matrix (Discussion #56787)
You can't, the env context documentation<https://docs.github.com/en/actions/learn-github-actions/contexts#env-context> describes it pretty clearly:
You can use the env context in the value of any key in a step except for the id and uses keys.
A job output would work there. Small catch: The value of an output is a string. If you want to define an array from it, that string must be valid JSON defining the array. Then use fromJSON()<https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson> to turn the JSON into an actual array (see the examples behind that link).
-
Reply to this email directly, view it on GitHub<#56787 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ASLCJX3OISP23SXDOVOSNCDXIZD4VANCNFSM6AAAAAAYUNMXCY>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
PRIVILEGED AND CONFIDENTIAL This e-mail is intended only for the named person or entity to which it is addressed and contains valuable business information that is privileged, confidential and/or otherwise protected from disclosure. If you have received it in error, please delete it immediately and notify the sender.
|
Beta Was this translation helpful? Give feedback.
-
Where it is available, yes.
You missed an important part of the quote: anywhere in a step. So only within the
With the method I described above: By adding a job that creates the string as an output. Ironically the step within that job that sets the output could copy it from |
Beta Was this translation helpful? Give feedback.
-
|
I have one more doubt, the attached screenshot is the summary of my workflow: One problem I am facing now is, that I can’t re-trigger the whole 3rd and 4th job separately, instead I can just trigger one matrix job within it. Am I making any coding mistakes in the workflow, let me know in case you want more information. |
Beta Was this translation helpful? Give feedback.
-
|
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
-
|
kind of weird that this is not possible in 2024. i have several jobs that should use the same strategy. what is an easy way to define the strategy once and reuse it across jobs? |
Beta Was this translation helpful? Give feedback.



Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Question
Body
Hi, I have trying to resolve an issue with github actions workflow, can I give an env variable in strategy matrix instead of mentioning it explicitly in the matrix. e.g instead of this:
jobs:
Backup_ServerCopy:
runs-on: [self-hosted]
needs: Clone
strategy:
matrix:
vhost_loop: [abc.com,xyz.com]
steps:
- run: <command#1 taking matrix.vhost_loop as an argument>
- run: <command#2 taking matrix.vhost_loop as an argument>
if I can some how use it like this:
env:
vhosts: [abc.com,xyz.com]
jobs:
Backup_ServerCopy:
runs-on: [self-hosted]
needs: Clone
strategy:
matrix:
vhost_loop: ${{ env.vhosts }}
steps:
- run: <command#1 taking matrix.vhost_loop as an argument>
- run: <command#2 taking matrix.vhost_loop as an argument>
Beta Was this translation helpful? Give feedback.
All reactions