Add boolean negation and ternary operator to interpolation function

Component input interpolation is too limited.
Common patterns require job duplication or complex rules.


Proposal

  1. Boolean inversion

Adding boolean negation could be implemented as:

  • ! inputs.strict
  • or not inputs.strict

Example:

test:job:
  allow_failure: $[[ ! inputs.strict ]]
  1. Ternary operator

Allow conditional expressions in interpolation, current workaround (duplicated jobs):

test:job:cache:
  rules:
    - if: '"$[[ inputs.cache_url ]]" != ""'
  script:
    - my_cmd --cache-url $[[ inputs.cache_url ]]

test:job:no-cache:
  rules:
    - if: '"$[[ inputs.cache_url ]]" == ""'
  script:
    - my_cmd

Proposed:

test:job:$[[ inputs.cache_url != "" ? "cache" : "no-cache" ]]
  script:
    - my_cmd $[[ inputs.cache_url != "" ? "--cache-url " + inputs.cache_url : "" ]]

Note

The ternary example uses string concatenation ("--cache-url " + inputs.cache_url) to illustrate a possible use case. Support for string operations (such as concatenation) could be addressed separately. This proposal focuses on conditional selection, not on defining a full expression or string-manipulation language.


Benefits

  • Fewer duplicated jobs.
  • Cleaner components.
  • Easier maintenance.
Edited by 🤖 GitLab Bot 🤖