How can I use variables stored with envman in the run_if check before a step is run?

For example, this works fine:

run_if: '{{(getenv "BITRISE_BUILD_STATUS") | eq "0"}}'

But trying to use a variable I defined via envman in an earlier step does not work. Is this expected behavior? Is there a way around this?


Hi @vince.delricco,

You can reference those vars exactly the same as any env var, as those are just regular env vars.

Are you sure that the env var is actually set, and that you have the exact same env var in the run_if? Can you please include the related bitrise.yml config or link a related build’s URL?

Hi @viktorbenei,

I was able to get past my issue, thank you for confirming that this is possible. To give you more context, this is the scenario that was not working for me:

    - script@1.1.5:
        is_always_run: true
        - content: |-
            echo 0 | envman add --key TEST_ENV       
    - script@1.1.5:
        is_always_run: true
        run_if: '{{getenv "TEST_ENV" | eq "0"}}'
        - content: |-
            echo "Test!!"

The second script would never be called, and I would always see the output:

WARN[16:35:01] The step's (script@1.1.5) Run-If expression evaluated to false - skipping
INFO[16:35:01] The Run-If expression was: {{getenv "TEST_ENV" | eq "0"}}

All I had to do was to change the way I was setting the TEST_ENV to the following:

envman add --key TEST_ENV --value 0

and the second script would run and I would see Test!! printed.

I’m sure this is a case of me not understanding what BASH is doing behind the scenes here, but wanted to provide the solution that worked for me.

Thanks again @viktorbenei!


Thanks for sharing the scripts @vince.delricco!

Indeed, there’s a subtle difference between the two versions. Actually it’s the way how echo without flags work: echo adds a newline to the end of the printed value unless you set the -n flag for it.

So, echo 0 actually will be 0\n, not just 0. The getenv func does a string compare, which of course will not be true for "0" == "0\n".

Using the --value flag of envman the value will not include the trailing newline, or echo -n 0 should also do the trick :wink: