I am using Azure DevOps YAML pipelines and have two stages - one is deploying to dev (is triggered by commit in master), and the second is checking pull requests (running tests and static analysis). These stages are executed based on variables, e.g. variables['Build.Reason']
or variables['Build.SourceBranchName']
.
The pull request checks are set as required in branch policy, so the pipeline must pass before the author can merge it.
What I want is to allow the author to manually trigger deploy to dev from pull request (e.g. because there are changes in infrastructure, environment variables, etc.) to make sure everything works before the changes are merged upstream.
Example 1: I am changing just one function. I want the pipeline to run the static analysis and tests successfully and then merge the PR.
Example 2: I am integrating a new external service (e.g. emailing) and I want to make sure everything works. So the pipeline will trigger static analysis and tests and finish successfully (and would allow me to merge if I wanted to). However, because it is a bigger change with external integrations, at this point I want to trigger deploy to dev and check if everything works. This is still done from PR, not from the master, because I want to fix issues if they occur before the change is upstream.
In both cases (Example1 as well as Example2), after mege to master changes will be deployed to dev.
What I tried so far
ManualValidation@0
task: not applicable, because then the pipeline is not successful. As the pipeline is required to pass before the merge request, the author can't merge it without the deployment to dev.DeployDevFromPR
, that should indicate whether the pipeline should check to code, or deploy it. Then set two branch policies, one automatic and required (the checks) and one manual and optional (the deployment). However, there is no possibility to set the env variable from the PR view (unless the author requeue the pipeline again), so the manual step runs the check.variables['Build.QueuedBy']
: the value is different when pipeline is triggered automatically. For user, there is its username, but for automatic triggers there is "Microsoft.VisualStudio.Services.TFS". However, this breaks if the user wants to rerun the check pipeline (then the QueuedBy will be the user).Can I somehow get to the desired effect to allow user deploy from PR manually without blocking the merge?
Thank you
I am using Azure DevOps YAML pipelines and have two stages - one is deploying to dev (is triggered by commit in master), and the second is checking pull requests (running tests and static analysis)
Instead of using a single pipeline with 2 stages consider splitting the pipeline in two:
After splitting the pipelines, create a build policy in the Build Validation section for each one:
Example of a policy for the Deploy pipeline: