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

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?

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

:wave: We’re just in the process of making this easier now! Here are some docs:

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

  - command: ""
    if: "build.pull_request.base_branch == 'master'"

Let me know how you go!

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

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

That works perfect for me. Thanks.

1 Like