question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conditional operator or function for expression syntax

See original GitHub issue

Describe the enhancement

I’d like some kind of conditional operation added to expression syntax. This can be an actual ternary operator (? :) or a built-in function (e.g., if(<condition>, <true-value>, <false-value>)).

Additional information

There is a workaround: using shell scripts to evaluate the condition, setting step outputs, and having other steps reference those outputs. But it would be much cleaner to have some kind of ternary / if/then/else / conditional branching built in to the expression syntax.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:351
  • Comments:16

github_iconTop GitHub Comments

225reactions
molszanskicommented, Dec 30, 2020

Syntax: ${{ x && 'ifTrue' || 'ifFalse' }}

fake ternary example

    steps:
      - name: stuff
        env:
          PR_NUMBER_OR_MASTER: ${{ github.event.number == 0 && 'master' ||  format('pr-{0}', github.event.number)  }}

on condition is that your first <true-value> must be true for this to work

86reactions
ylemkimoncommented, Nov 15, 2020

It seems, although not identical, <condition> && <true-value> || <false-value> works in most cases.

Read more comments on GitHub >

github_iconTop Results From Across the Web

the ternary conditional operator
Learn about the C# ternary conditional operator, (`?:`), that returns the result of one of the two expressions based on a Boolean ...
Read more >
Ternary conditional operator
In computer programming, the ternary conditional operator is a ternary operator that is part of the syntax for basic conditional expressions in several ......
Read more >
Conditional Operator in C
Syntax of a conditional operator · #include <stdio.h> · int main() · { · int age; // variable declaration · printf("Enter your age");...
Read more >
Conditional or Ternary Operator (?:) in C
The conditional operator or ternary operator in C is generally used when we need a short conditional code such as assigning value to...
Read more >
JavaScript Ternary Operator – Syntax and Example Use ...
The ternary operator is a conditional operator which evaluates either of two expressions – a true expression and a false expression – based...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found