Conditionally run a step only if a secret is defined?

I’d like to add a step to my workflow which only runs if a specific named secret has been defined.

I tried this but it didn’t work:

if: secrets.MY_SECRET

Hi @simonw,

Please use below format instead. secrets.* is not recognized in if expression. You can set it as env and read via env.*.

      - name: check
        if: contains(env.TESTKEY1, 'value1')         # use env value instead.
        run: |
          echo test
        env:
            TESTKEY1: ${{secrets.TESTKEY1}}         

Thanks

2 Likes