Run_if supports contains function

Hello bitrise community,

According to Enabling or disabling a Step conditionally, there is a usage of envcontain function to check if the environment variable contains a substring. However, it doesn’t work when I tried to test in my configuration. Could you please verify, is it a outdated feature which was removed or could you help me to find a way how to check if environment variable contains a substring in run_if section?

image

Hi @akniyet :wave:

envcontain is still in the CLI’s code, so it should work: bitrise/bitrise/template_util.go at f5fadde8ae038f6a2b1ca21f82089adfc736d143 · bitrise-io/bitrise · GitHub

I just tested it with the following bitrise.yml and it worked as expected (Bitrise CLI v2.13.1):

format_version: "11"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: other
workflows:
  primary:
    envs:
    - MY_TEST_ENV: 'A B C'
    steps:
    - script@1:
        run_if: '{{envcontain "MY_TEST_ENV" "B"}}'
        title: Do anything with Script step
    - script@1:
        run_if: '{{envcontain "MY_TEST_ENV" "D"}}'
        title: Do anything with Script step

The first step was performed, the second one was skipped:

+------------------------------------------------------------------------------+
| (0) Do anything with Script step                                             |
+------------------------------------------------------------------------------+
| id: script                                                                   |
| version: 1.2.1                                                               |
| collection: https://github.com/bitrise-io/bitrise-steplib.git                |
| toolkit: bash                                                                |
| time: 2024-05-12T17:47:26+02:00                                              |
+------------------------------------------------------------------------------+
|                                                                              |
+ echo 'Hello World!'
Hello World!
|                                                                              |
+---+---------------------------------------------------------------+----------+
| ✓ | Do anything with Script step                                  | 2.12 sec |
+---+---------------------------------------------------------------+----------+

                                        ▼

+------------------------------------------------------------------------------+
| (1) Do anything with Script step                                             |
+------------------------------------------------------------------------------+
| id: script                                                                   |
| version: 1.2.1                                                               |
| collection: https://github.com/bitrise-io/bitrise-steplib.git                |
| toolkit: bash                                                                |
| time: 2024-05-12T17:47:28+02:00                                              |
+------------------------------------------------------------------------------+
|                                                                              |
This Step was skipped, because its "run_if" expression evaluated to false.
The "run_if" expression was: {{envcontain "MY_TEST_ENV" "D"}}
|                                                                              |
+---+---------------------------------------------------------------+----------+
| - | Do anything with Script step (Skipped)                        | 0.40 sec |
+---+---------------------------------------------------------------+----------+


+------------------------------------------------------------------------------+
|                           bitrise summary: primary                           |
+---+---------------------------------------------------------------+----------+
|   | title                                                         | time (s) |
+---+---------------------------------------------------------------+----------+
| ✓ | Do anything with Script step                                  | 2.12 sec |
+---+---------------------------------------------------------------+----------+
| - | Do anything with Script step (Skipped)                        | 0.40 sec |
+---+---------------------------------------------------------------+----------+
| Total runtime: 2.52 sec                                                      |
+------------------------------------------------------------------------------+

Are you sure that you have TEST_KEY set to a value which includes test value? (referring to the screenshot you shared)

Hi Viktor, sorry for late response, I found the cause,
As you confirmed it works on workflow checks, however I tried to do on pipeline level, which is not supported yet

1 Like