Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 3

If expression with context variable

It would be nice the possibility to do the following, i.e. conditional steps from the existence of a given element of the context:

jobs:
myjob:
step:
- name: Deploy step
if: secrets.MY_SECRET

Also a exists(secrets.MY_SECRET) would be ok.

 

In any case, it would be nice accessing the context from if statements. I tried the following but it didn't work (Unrecognized named-value: 'secrets'):

jobs:
myjob:
step:
- name: Deploy step
if: format('{{{0}{1}}}', ${{ secrets.MY_SECRET }}, "x") == "x"

This second case is a workaround attempt for this specific case, though it can be generalized to the access of the build context from if statements.

Partially related to https://github.community/t5/GitHub-Actions/Support-for-use-of-environment-variables-in-if-expression....

2 Replies
Pilot Lvl 2
Message 2 of 3

Re: If expression with context variable

This can be workarounded by passing secret as env variable and then check if variable is empty (either directly in workflow or inside deploy script, if any).

 

 missing-secret-if:
  runs-on: ubuntu-latest

  steps:
  - run: echo YAY
  - run: |
         if [ "$MY_SECRET" != "" ]; then
            echo WOOHOO
         fi
    env:
     MY_SECRET: ${{ secrets.DOES_NOT_EXIST }}
Copilot Lvl 2
Message 3 of 3

Re: If expression with context variable

Yes that is a valid workaround, thanks. Though, the step is executed in any case and from the workflow execution it is marked as succeed even if is was no-op. This might be misleading.

 

I wait for someone from the staff to chime in, maybe they have some comment on the feature request.