Accessing secrets by index using an environment variable #25171
-
Hi all! At this moment I am creating a pipeline in which I would like to achieve the following:
To make this more clear, I added a code snippet:
So based on the set environment variable I would like to access: secrets.PROD I used: https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions as a reference. Any help or direction would be appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I’m not sure whether that is possible. I use something similar in one of my workflows (see here). I believe environments variables are referenced in a different way that you’re doing since this is about environment variables between different steps. You should use “env.ENVIRONMENT” to reference an environment variable. The following example should echo “PROD”
Note that you could use bash in a step to selectively get an environmnet variable (also see my workfow for bash in a “run” step. Hope this helps any. |
Beta Was this translation helpful? Give feedback.
-
Hi @nilsdebruin, Accessing secrets by index using an environment variable is not supported.
|
Beta Was this translation helpful? Give feedback.
-
Hi all, Thanks for the replies! I have now come up with the following solution (which works, but does not feel dry):
This works for my use case, so thanks for your help and input! |
Beta Was this translation helpful? Give feedback.
Hi @nilsdebruin,
Accessing secrets by index using an environment variable is not supported.
As a workaround , you could add another step with if conditional for non-production . And you could use secrets.PROD directly when set a step environment variable.