2
votes

In VSTS, I have a GIT repo and a build def with 5 tasks in it. I have added a branch policy on master branch wherein the build will run when a pull-request is created as a part of check-in policy. I run that same build as a CI build as well when code is merged from feature branch to master branch.

Now I need to make sure the build runs as part of Pull-Request then only top 4 tasks should be executed and when that same build is run as part of CI(trigger) then all the 5 tasks should get executed.

I cannot find any such out-of-the-box option in VSTS to do this. So need help on this.

1

1 Answers

6
votes

In the last task (the task you want to run only in CI) add a custom condition:

and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))

enter image description here

Now in a Pull Request, the task will not be executed.