这是我的解决方案,在同一个 Azure 组织中,我们可以创建一个 Azure 项目,然后创建一个存储库来保存通用管道模板。其他 Azure 项目中的所有 repos 都可以访问此管道模板。

UserProject/UserRepo/azure-pipelines.yml
trigger:
branches:
include:
- master
paths:
exclude:
- nuget.config
- README.md
- azure-pipelines.yml
- .gitignore
resources:
repositories:
- repository: devops-tools
type: git
name: PipelineTemplateProject/CommonPipeline
ref: 'refs/heads/master'
jobs:
- template: template-pipeline.yml@devops-tools
PipelineTemplateProject/CommonPipeline/template-pipeline.yml
由于 pipeline 的内联脚本有 5000 个字符的限制,您可以将您的脚本(不仅是 powershell,还包括其他语言)放在 PipelineTemplateProject/CommonPipeline/scripts/test.ps1
# Common Pipeline Template
jobs:
- job: Test_Job
pool:
name: AgentPoolName
steps:
- script: |
echo "$(Build.RequestedForEmail)"
echo "$(Build.RequestedFor)"
git config user.email "$(Build.RequestedForEmail)"
git config user.name "$(Build.RequestedFor)"
git config --global http.sslbackend schannel
echo '------------------------------------'
git clone -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" -b $(ToolsRepoBranch) --single-branch --depth=1 "https://PipelineTemplateProject/_git/CommonPipeline" DevOps_Tools
echo '------------------------------------'
displayName: 'Clone DevOps_Tools'
- task: PowerShell@2
displayName: 'Pipeline Debug'
inputs:
targetType: 'inline'
script: 'Get-ChildItem -Path Env:\ | Format-List'
condition: always()
- task: PowerShell@2
displayName: 'Run Powershell Scripts'
inputs:
targetType: filePath
filePath: 'DevOps_Tools/scripts/test.ps1'
arguments: "$(System.AccessToken)"
注意:组织设置-设置-禁用限制工作授权范围到当前项目的发布管道
组织设置 - 设置 - 将工作授权范围限制为非发布管道的当前项目
检查项目设置中的一些选项。

所以普通用户只能访问自己的repo,不能访问DevOps项目,DevOps所有者只能编辑模板管道。
对于通知问题,我使用电子邮件扩展“rvo.SendEmailTask.send-email-build-task.SendEmail@1”