'How to remove/lock branch selection when queuing new Azure DevOps pipeline
Solution 1:[1]
I don't think it's possible, as a workaround you can add a small PowerShell script that checks the branch and if it's not the master fail the build:
if("$(Build.SourceBranchName)" -ne "master")
{
Write-Error "The branch is not the master!"
}
Solution 2:[2]
It seems to not be possible to limit that.
What we do is to add a condition to the build stage and make all other stages dependent of build.
condition: startsWith(variables['Build.SourceBranch'], 'refs/heads/master')
This way, build will be skipped if it is not on master and all other stages will be skipped as well as they depends on build.
Solution 3:[3]
I would also like to remove possibility to change branch when queuing a build.
For this issue , as a workaround ,you can set the user's access level to Stakeholder. Users with Stakeholder access level cannot change branch during queue build.
The following page will be displayed during Stakeholder queue build, and the branch will be in the loading state,but this does not affect users to run the pipeline.
The reason for the error is that Stakeholder does not have read repo permission, and the Repos column will not be displayed in the menu bar. So the disadvantage of this setting is that the users cannot access repos.
Except this method, it is impossible to achieve this feature.There are currently no permissions in Azure devops can achieve this. You could also add your request for this feature on our UserVoice site, which is our main forum for product suggestions.More votes and comments can increase the priority of feedback.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shayki Abramczyk |
| Solution 2 | LcRok |
| Solution 3 |


