# How can I let build agent only run a build step on a PR to master branch?

**URL:** <https://forum.buildkite.community/t/how-can-i-let-build-agent-only-run-a-build-step-on-a-pr-to-master-branch/714>\
**Category:** General\
**Created:** [October 1, 2019, 10:05am UTC](https://forum.buildkite.community/t/how-can-i-let-build-agent-only-run-a-build-step-on-a-pr-to-master-branch/714 "2019-10-01T10:05:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joeyzhao](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@joeyzhao](https://forum.buildkite.community/u/joeyzhao)\
**Post date:** [October 1, 2019, 10:05am UTC](https://forum.buildkite.community/t/how-can-i-let-build-agent-only-run-a-build-step-on-a-pr-to-master-branch/714/1 "2019-10-01T10:05:16Z")

</div>

I am using `pipeline.yml` to define all build steps and I want one of the build step to be run only when there is a pull request to master branch. How can I add this filter on pipeline?

---

<div class="post-metadata">

**Author:** ![jufemaiz](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/jufemaiz/32/1693_2.png) [@jufemaiz](https://forum.buildkite.community/u/jufemaiz)\
**Post date:** [October 2, 2019, 5:55am UTC](https://forum.buildkite.community/t/how-can-i-let-build-agent-only-run-a-build-step-on-a-pr-to-master-branch/714/2 "2019-10-02T05:55:19Z")

</div>

I believe you’ll need to use a dynamic pipeline. PR to master as a conditional requirement to generate the next step.

---

<div class="post-metadata">

**Author:** ![anon85971592](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@anon85971592](https://forum.buildkite.community/u/anon85971592)\
**Post date:** [October 3, 2019, 10:38am UTC](https://forum.buildkite.community/t/how-can-i-let-build-agent-only-run-a-build-step-on-a-pr-to-master-branch/714/3 "2019-10-03T10:38:16Z")

</div>

👋 We’re just in the process of making this easier now! Here are some docs: [https://buildkite.com/docs/pipelines/conditionals](https://buildkite.com/docs/pipelines/conditionals)

In your case @joeyzhao, you’ll want to do something like this:

```auto
steps:
  - command: "test.sh"
    if: "build.pull_request.base_branch == 'master'"

```

Let me know how you go!

---

<div class="post-metadata">

**Author:** ![joeyzhao](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@joeyzhao](https://forum.buildkite.community/u/joeyzhao)\
**Post date:** [October 3, 2019, 11:07am UTC](https://forum.buildkite.community/t/how-can-i-let-build-agent-only-run-a-build-step-on-a-pr-to-master-branch/714/4 "2019-10-03T11:07:24Z")

</div>

Thanks for your reply. Could you let me know when you will release this feature?

---

<div class="post-metadata">

**Author:** ![anon85971592](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@anon85971592](https://forum.buildkite.community/u/anon85971592)\
**Post date:** [October 3, 2019, 11:27pm UTC](https://forum.buildkite.community/t/how-can-i-let-build-agent-only-run-a-build-step-on-a-pr-to-master-branch/714/5 "2019-10-03T23:27:38Z")

</div>

@joeyzhao it’s already been shipped as stable, so it works right now. We just haven’t written a changelog for it.

---

<div class="post-metadata">

**Author:** ![joeyzhao](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@joeyzhao](https://forum.buildkite.community/u/joeyzhao)\
**Post date:** [October 4, 2019, 5:37am UTC](https://forum.buildkite.community/t/how-can-i-let-build-agent-only-run-a-build-step-on-a-pr-to-master-branch/714/6 "2019-10-04T05:37:44Z")

</div>

That works perfect for me. Thanks.
