Skip to content

Commit 5794693

Browse files
authored
Restore example of conditional logic in expressions
1 parent 62372d0 commit 5794693

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

content/actions/reference/workflows-and-actions/expressions.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ env:
8383

8484
{% 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.
8585

86+
### Example
87+
88+
{% raw %}
89+
90+
```yaml
91+
env:
92+
MY_ENV_VAR: ${{ github.ref == 'refs/heads/main' && 'value_for_main_branch' || 'value_for_other_branches' }}
93+
```
94+
95+
{% endraw %}
96+
97+
In this example, we're using a combination of `&&` and `||` operators 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`. It is important to note that the first value after the `&&` must be truthy. Otherwise, the value after the `||` will always be returned.
98+
8699
## Functions
87100

88101
{% data variables.product.prodname_dotcom %} offers a set of built-in functions that you can use in expressions. Some functions cast values to a string to perform comparisons. {% data variables.product.prodname_dotcom %} casts data types to a string using these conversions:

0 commit comments

Comments
 (0)