Skip to content

Use default value on empty variable of an action

ChristopherHX edited this page Feb 17, 2024 · 1 revision

Some hidden additional information about default values you might never saw before

(undocumented) easter egg (since second half of 2019, inherited from azure pipelines) of actions/runner allows to trigger the default on empty var

      - name: test with possibly no value
        uses: ./
        with:
          ${{ insert }}: |-
            ${{ vars.something
            && fromjson(format('{{"test": {0}}}', tojson(vars.something)))
            || fromjson('{}') }}

actually pretty ugly and act will fail when it would see it

Trivia the much better to read if, elseif and else syntax of Azure Pipelines are not available in GitHub Actions

This case would collapse to case 1 if vars.something is empty, otherwise would result in case 2.