Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow PR Build Validation builds without publishing artifacts

I'm trying to set up some build validation for PR's on our master branch (We're using Git and VSTS). I added some build policies to kick off various builds depending on what files have changed. For some background, we create PR's somewhat early in the process so we can track changes and add comments as our feature branch is developed.

Now, I want these builds to run and succeed in order for a PR to be completed, however, I don't want the output (artifacts) from these builds to be published. Our publishes look at the latest build artifact to deploy, and in this case, the latest build artifact would be from the PR. If we did allow these build artifacts from the PR to be published, then we'd be publishing feature branch code (which came from the PR) to our main site, which isn't desirable (we have a separate publish to handle our feature branch sites).

Essentially, when doing a PR, I just want to run the build to make sure that everything is kosher, and then throw away the build once it's completed.

Outside of creating a build definition solely for PR validation, I'm not sure what I can do. I've googled and asked around, but I'm either not asking the right questions, or the answer isn't as simple as I hope.

Hopefully I've included enough details to explain my problem.

TL;DR

How can I run build validations on a PR without having a publish pick up and deploy the build artifact that resulted from the validation build?

Edit (More details)

I tried adding conditions to the publish task (also tried putting the publish in a phase and conditionally running that). However, when I go to make a new release, it still sees the build definition that was run. Now, I imagine that if I tried to release that build definition, it would fail because no artifact was created. But I don't even want to see that build definition when I'm doing a release (don't want to accidentally select it).

like image 382
Andrew Avatar asked Dec 23 '22 06:12

Andrew


1 Answers

You could put the Publish Artifact task its own Phase at the end of your build definition then use 'Run this phase' with 'Custom condition using variable expressions'. You can also do this at the Task level as Dan suggested in the comment below.

not(eq(variables['Build.Reason'], 'PullRequest'))

https://learn.microsoft.com/en-us/vsts/pipelines/process/conditions?view=vsts

like image 187
Calidus Avatar answered Dec 26 '22 09:12

Calidus