# Expressing \`not includes\` in \`if\` condition?

**URL:** <https://forum.buildkite.community/t/expressing-not-includes-in-if-condition/1543>\
**Category:** General\
**Created:** [April 27, 2021, 8:51pm UTC](https://forum.buildkite.community/t/expressing-not-includes-in-if-condition/1543 "2021-04-27T20:51:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![evanrelf](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/evanrelf/32/827_2.png) [@evanrelf](https://forum.buildkite.community/u/evanrelf)\
**Post date:** [April 27, 2021, 8:51pm UTC](https://forum.buildkite.community/t/expressing-not-includes-in-if-condition/1543/1 "2021-04-27T20:51:16Z")

</div>

I would like to choose between two steps, depending on whether the GitHub pull request has a particular label. Something like this:

```yaml
steps:
  - command: "echo normal"
    if: !(build.pull_request.labels includes "experimental")
    
  - command: "echo experimental"
    if: build.pull_request.labels includes "experimental"

```

However this doesn’t seem to work. What I _really_ want is a `BUILDKITE_PULL_REQUEST_LABELS` environment variable so I can change behavior in the `command`, but that isn’t available, so I’m trying to pick between two jobs using `built.pull_request.labels`.

---

<div class="post-metadata">

**Author:** ![evanrelf](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/evanrelf/32/827_2.png) [@evanrelf](https://forum.buildkite.community/u/evanrelf)\
**Post date:** [April 27, 2021, 9:23pm UTC](https://forum.buildkite.community/t/expressing-not-includes-in-if-condition/1543/2 "2021-04-27T21:23:20Z")

</div>

For now I’m able to get away with querying the GitHub API directly, however I think the `!(array includes "item")` syntax makes sense and is sorely lacking in Buildkite.

---

<div class="post-metadata">

**Author:** ![sj26](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/sj26/32/17_2.png) [@sj26](https://forum.buildkite.community/u/sj26)\
**Post date:** [April 28, 2021, 1:55am UTC](https://forum.buildkite.community/t/expressing-not-includes-in-if-condition/1543/3 "2021-04-28T01:55:14Z")

</div>

Hi @evanrelf!

Using `!(...)` should work, but perhaps you’re having trouble because starting a value with “!” has special meaning in YAML sorry. This syntax should work:

```auto
steps:
  - command: "echo normal"
    if: |
      !(build.pull_request.labels includes "experimental")
    
  - command: "echo experimental"
    if: build.pull_request.labels includes "experimental"

```

This site is useful for testing how YAML is being parsed:

[https://yaml-online-parser.appspot.com](https://yaml-online-parser.appspot.com)

---

<div class="post-metadata">

**Author:** ![evanrelf](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/evanrelf/32/827_2.png) [@evanrelf](https://forum.buildkite.community/u/evanrelf)\
**Post date:** [April 30, 2021, 10:40pm UTC](https://forum.buildkite.community/t/expressing-not-includes-in-if-condition/1543/4 "2021-04-30T22:40:21Z")

</div>

Ahh I see, thank you! YAML nuances strike again 🙂

---

<div class="post-metadata">

**Author:** ![evanrelf](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/evanrelf/32/827_2.png) [@evanrelf](https://forum.buildkite.community/u/evanrelf)\
**Post date:** [May 3, 2021, 8:20pm UTC](https://forum.buildkite.community/t/expressing-not-includes-in-if-condition/1543/5 "2021-05-03T20:20:12Z")

</div>

One thing to note: exposing PR labels only in the `if` attribute of the step, and not as an environment variable in the `command` environment, means you’re forced to choose different `key`s for each possible job.

In the example I gave, the “normal” and “experimental” job would require different `key`s, so you’d need to be aware of that when writing `depends_on` attributes in later steps.

In my case, this isn’t a problem. But I still think a hypothetical `BUILDKITE_PULL_REQUEST_LABELS` variable would be a better solution than the workaround I’m doing here.
