Check whether environment variable is empty

Viewed 9484

What is the nicest approach to check if environment variable is empty on Github action as a condition to a step? I've tried the trivial approach but it doesn't seem to work.

For example:

name: SimpleWorkflow

on:
  push:   

env:
  MULTI_LINE_ARG: |
  ARG1: value
jobs:
  update:
    runs-on: ubuntu-latest
    steps:
      - name: Fetching Local Repository
        uses: actions/checkout@master
      - name: run step if multiline not null
        if: ${{env.MULTI_LINE_ARG}} != ""
        run: echo multiline not null     

No matter how I've tried this I fail to properly check if env is empty.

1 Answers

Background: The issue of secrets not available to forks is known to GitHub folks, but no concrete activity announced: https://github.community/t/github-workflow-not-running-from-pull-request-from-forked-repository/16379/41?u=koppor

One can use output variables of steps to determine whether a secret is available.

      - name: Check secrets presence
        id: checksecrets
        shell: bash
        run: |
          if [ "$MULTI_LINE_ARG" == "" ]; then
            echo ::set-output name=secretspresent::false
          else
            echo ::set-output name=secretspresent::true
          fi
        env:
          MULTI_LINE_ARG: ${{ secrets.MULTI_LINE_ARG}}
      - name: run step if multiline not null
        if: ${{ steps.checksecrets.outputs.secretspresent }}
        run: echo multiline not null

Note: Solution adapted from https://github.community/t/if-expression-with-context-variable/16558/6?u=koppor.

Related