Jeevan
Jeevan

Reputation: 437

Azure DevOps how to skip PublishBuildArtifacts step for PR build runs

I am using Azure DevOps and I have a single build pipeline with a number of steps including PublishBuildArtifacts defined in the azure-pipelines.yml file.

I have pointed the same pipeline for the Build Validation (Validate code by pre-merging and building pull request changes.) from the master branch's build policies option. However, for this PR build run, I don't to run certain tasks like PublishBuildArtifacts.

How can I achieve this? I can think of one way which is to create a separate pipeline for PR and also a separate azure-pipelines-pr.yml file and not adding those tasks in that file. But this feels like an approach with redundancy to me. Is there any better way to achieve this?

Upvotes: 4

Views: 2280

Answers (1)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41555

You can add a custom condition for the publish artifacts step:

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

Now the step will run only when the build reason is not pull request.

Upvotes: 4

Related Questions