Skip running the e2e tests for some pipelines

Hi team,

I have this on my condition where if the build/source pipeline has null or ‘’ value for this CI variable: SPECS then it should skip running the command. However, it seems it still triggers the command.

steps:
  - label: 'Run e2e tests'
    if: build.env('SPEC') != null || build.env('SPEC') != ''
    commands:
    - npx cypress run --spec $SPEC --parallel --ci-build-id $BUILDKITE_BUILD_NUMBER

The reason I use build.env is because this is triggered from another pipeline. Sample build/source pipeline:

trigger: "e2e-tests"

I checked the Environment details and it shows SPEC="" so I am not sure why its not passing the if condition.

Hey @ebanster!

Hope you’re well - thanks for the message :wave:

Configuration looks fine on my side - would you be able to give just the null check an attempt? A setup like such should assist:

Parent trigger build (note I am not setting a TEST_ONE environment variable through to the triggered build

steps:
  - label: ":pipeline: Trigger"
    trigger: "triggered"
    build:
      branch: main
      env:
        TEST_TWO: "one"

In the triggered pipeline’s build - the second echo shouldn’t print:

steps:
  - command: "This will print"
  - if: build.env('TEST_ONE') != null
    command: echo "This should not print"

Note I’m using the latest agent version (3.54.0).

Hope that helps!

Thanks mate. That was my original condition but it didn’t work so I include an OR statement to include ‘’:
if: build.env('SPEC') != null

I am using 3.47.0 agent

No worries @ebanster!

I’ve also tried out those exact steps for my triggering/triggered pipelines on 3.47.0 too - an the original null check for a environment variable that isn’t set doesn’t print as expected (doesn’t matter if I add the build.env attributes or leave those attributes empty and have a simple trigger:

Curious - are you setting any additional attributes on your trigger step - or is it just the one-liner as you’ve shown above?

This is what it looks like:

    trigger: "e2e-tests" # triggers the e2e tests sitting on a separate repo
    build:
      env:
        SPEC: ${SPEC} # pass the variables set in Build Steps
    soft_fail: true # even if tests fail, it can still move to the next CI steps below

Also, I’m happy to share the whole thing and the builds via support email if that makes it easier to help debug.

Cheers - looks as what I’d expect normally! (assuming as it’s said there that the SPEC variable is defined in the build’s commands)

You could implement a default in the build.env attribute of the trigger to look something like SPEC: ${SPEC:-} (note the :-) as when thats passed through, the variable will be set as an empty string on the triggering build. That way if its defaulted (hence not set) - the npm command can be bypassed:

env:
  SPEC: "defined"

steps:
  - label: ":pipeline: Trigger"
    trigger: "triggered"
    build:
      branch: main
      env:
        SPEC: ${SPEC:-}

Thanks James.
Can I just double confirm that is a good one?

trigger: "e2e-tests" # triggers the e2e tests sitting on a separate repo
    build:
      env:
        SPEC: ${SPEC:-} # pass the variables set in Build Steps

with the above, when SPEC = “” it will skip the npm run and nothing will happen. And when it has any value, it will simply run the command?

Correct @ebanster - and no worries too!

In that definition above, the SPEC variable isn’t defined and thus will be resultant as "" on the trigger, and will skip the command with said conditional. If it is set of course, either by upper level env (like in my example) or set on the command steps itself before the trigger - that conditional will resolve true and will run.

Hope that assists :+1:

This topic was automatically closed after 3 days. New replies are no longer allowed.