MicrosoftPremier / VstsExtensions

Documentation and issue tracking for Microsoft Premier Services Visual Studio Team Services Extensions
MIT License
59 stars 14 forks source link

How to set Branch policy execution order. #123

Closed Anvas007 closed 3 years ago

Anvas007 commented 3 years ago

Hello,

My scenario is bit complicated but I hope I get some input from here!!!

I am using Azure DevOps pipeline and Git repository. Scenario is : I need to set up a branch policy to a branch in such a way that

  1. There should be a reviewer
  2. A work item should be attached
  3. A gated pipeline build has to run before committing the code to the branch (Note Imp: as part of the gated build we have creating a delta file for database upgrade. and this delta file will commit as part of the gate)

Now the issue : I have configured the policy in git master branch as mentioned above. And I have created a pull request to master. As expected the gated build started execution and it created a delta file and committed the file to master before completing the pull request. if some one reject the pull request then the delta file created will remain orphan.

Is there any way I could wait the gated build to start only after the review completed? or any API available to check the status of the branch policy in the pipeline?

Thanks In advance Anvas K Happy Coding !!!

ReneSchumacher commented 3 years ago

Hi @Anvas007,

actually, this isn't the best repo to get answers to questions like this (this is specifically for issue from a couple Azure DevOps extensions), but I'll try to help anyway ;-)

As far as I understood your scenario, you configured the build pipeline in the branch policy as a validation build. Those builds are always triggered for every update of the pull request as they are meant to provide a quality gate. In other words: if the build fails, you cannot approve the pull request (unless you make the build an optional policy). What I do not understand is how your pipeline can possible update the master branch. Or are you just talking about the local master branch on the pipeline agent?

Generating some files like your database delta script as part of a build pipeline generally comes with a couple issues. You usually cannot automatically commit those files to version control without creating some side-effects. In your case, a pipeline running for master could not commit (or more precisely push) the delta file to version control, because the branch is protected. The pipeline running for the pull request cannot commit (push) the delta file to the pull request source branch, because that would trigger the pipeline again and you might find yourself in an endless loop. The latter might work if you ensure that you only commit the delta file when there's actually a change to it. In that case your first build in the PR would trigger itself again only once. Not the most beautiful solution, but it could work.

My questions would be:

ReneSchumacher commented 3 years ago

Hi @Anvas007,

do you need additional help for this? Otherwise, I'll close the issue by the end of next week.