Possible to use conditional in the "env" section of a job? #25725
-
I have several use cases where the environment variables for a job change depending on if I am on the master branch or not, or for example if the build up to the point has failed. My code for sending a slack message based on build status looks something like this:
It would be much more convenient if I could instead combine this into a single code block which conditional env vars, something like this?
Is there a way to do this, or perhaps another creative, compact way of accomplishing the same goal? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
There is no support for a ternary operator, but there are workarounds. You can try the following:
A limitation here is that the value after Another pseudo ternary expression that I haven’t tested yet, but which should work in principle and doesn’t suffer from above limitation:
This relies on type coercion, an implicit cast from boolean |
Beta Was this translation helpful? Give feedback.
-
This is not supported currently. As a workaround, you can try to configure your workflow like as below:
|
Beta Was this translation helpful? Give feedback.
-
Thanks! I’ll try out both solutions and select one. |
Beta Was this translation helpful? Give feedback.
-
I would recommend |
Beta Was this translation helpful? Give feedback.
There is no support for a ternary operator, but there are workarounds. You can try the following:
A limitation here is that the value after
&&
must not be falsey, because in that case the||
(or)…