Implementing Dry Run Logic: If and env

Hey Guys,

I’m trying to implement some kind of Dry-Run Logic based on the branch name.

Everything works fine except the “if”:

-name: Extract Branch Name
run: echo "::set-env name=BRANCH::$(echo ${GITHUB_REF##*/})"

-name: Set Release Mode (branch == master)
if: env.BRANCH == 'master'
run: echo "::set-env name=CREATE_RELEASE::true"

-name: Set Dry Run Mode (branch != master)
if: env.BRANCH != 'master'
run: echo "::set-env name=CREATE_RELEASE::false"

-name: Create Release Name
run: echo "::set-env name=RELEASE_NAME::${BRANCH}-${GITHUB_RUN_NUMBER}"
-name: Build Info
run:"echo Running Build $GITHUB\_RUN\_NUMBER on Ref $GITHUB\_REF / Branch $BRANCH, Release = $RELEASE\_NAME / $CREATE\_RELEASE"  
-name: Checkout Code
if: env.CREATE_RELEASE == 'true'

This works just fine:

if: env.BRANCH == 'master'

What the correct syntax for boolean Env Variables?

if: env.CREATE_RELEASE == 'true'
if: env.CREATE_RELEASE == true
if: ${env.CREATE_RELEASE == true}
if: ${{env.CREATE_RELEASE == 'true'}} => Error evaluating expression '${{env.CREATE_RELEASE == 'true'}}' - (anonymous): Line 1:2 Unexpected token { (and 1 more errors)

Using the following in a with block works:

draft: ${{env.CREATE_RELEASE == 'false'}}



1 Like

@rowi1de ,

The value of environment variable will be converted to a string, although you set the value as a boolean.

So when you use this environment variable in the if conditional for a step, the correct syntax is

if: env.CREATE_RELEASE == 'true’

for example:

- name: Checkout
        if: env.CREATE_RELEASE == 'true'
        uses: actions/checkout@v2