Skip to content

Commit f286910

Browse files
Update evaluate-expressions-in-workflows-and-actions.md (#38230)
Co-authored-by: Sharra-writes <[email protected]>
1 parent e7aec5e commit f286910

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

content/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,7 @@ env:
109109
* {% data variables.product.prodname_dotcom %} ignores case when comparing strings.
110110
* Objects and arrays are only considered equal when they are the same instance.
111111

112-
{% data variables.product.prodname_dotcom %} offers ternary operator like behaviour that you can use in expressions. By using a ternary operator in this way, you can dynamically set the value of an environment variable based on a condition, without having to write separate if-else blocks for each possible option.
113-
114-
### Example
115-
116-
{% raw %}
117-
118-
```yaml
119-
env:
120-
MY_ENV_VAR: ${{ github.ref == 'refs/heads/main' && 'value_for_main_branch' || 'value_for_other_branches' }}
121-
```
122-
123-
{% endraw %}
124-
125-
In this example, we're using a ternary operator to set the value of the `MY_ENV_VAR` environment variable based on whether the {% data variables.product.prodname_dotcom %} reference is set to `refs/heads/main` or not. If it is, the variable is set to `value_for_main_branch`. Otherwise, it is set to `value_for_other_branches`.
126-
It is important to note that the first value after the `&&` must be truthy. Otherwise, the value after the `||` will always be returned.
112+
% data variables.product.prodname_dotcom %} provides a way to create conditional logic in expressions using binary logical operators (`&&` and `||`). This pattern can be used to achieve similar functionality to the ternary operator (`?:`) found in many programming languages, while actually using only binary operators.
127113

128114
## Functions
129115

0 commit comments

Comments
 (0)