最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

yaml - What is the ternary operator equivalent in GitHub Actions? - Stack Overflow

programmeradmin1浏览0评论

How do I write something like this? At the moment using a colon seems to break everything. Is there an equivalent?

run-name: Something Running ${{  (inputs.cache-retain  == 'true') ? '(with forced cache-retain)' : ''}}

e.g.

  • if true: 'Something running (with forced cache-retain)'
  • if false: 'Something running'

is what I'm looking for.

How do I write something like this? At the moment using a colon seems to break everything. Is there an equivalent?

run-name: Something Running ${{  (inputs.cache-retain  == 'true') ? '(with forced cache-retain)' : ''}}

e.g.

  • if true: 'Something running (with forced cache-retain)'
  • if false: 'Something running'

is what I'm looking for.

Share Improve this question edited Mar 28 at 14:59 dankoiDev asked Mar 28 at 14:41 dankoiDevdankoiDev 1336 bronze badges 1
  • 4 Note this is not really "in YAML"; inside ${{ }} you're writing a GitHub Actions expression. – jonrsharpe Commented Mar 28 at 14:54
Add a comment  | 

1 Answer 1

Reset to default 1

Github Actions doesn't support ternary expressions. But using this workaround should work:

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

run: Something Running ${{ inputs.cache-retain == true && "(with forced cache retain)" || "" }}
发布评论

评论列表(0)

  1. 暂无评论