azure - Azure devops 服务连接和中央管道
问题描述
我需要让多个团队访问 azure 中的共享资源。因此,我想限制人们如何发布对共享资源的更改。
这个想法是将服务连接的使用限制到特定管道,根据本文档。但是,如果管道存储在他们自己的仓库中,开发人员可以更改它。这不会给我足够的控制权。因此,我发现可以使用来自中央仓库的模板。使用共享存储库,然后允许我为模板建立一个服务连接吗?
所以我想如何做上面的事情是我需要为我的 BuildTemplates Repo 授予项目 X 一个服务连接。但这基本上只是访问 repo 并能够使用共享模板。然后在 BuildTemplates 存储库中,我可以为我的模板 A 建立一个服务连接。
现在,项目 X 中的开发人员 - 使用她自己的服务连接为她的管道创建她的部署和配置,其范围是她的资源。然后她从 BuildTemplates Repo 继承一个模板,并为模板 A 传递相关参数。
由于范围服务连接,她无法更改模板管道 A,并且只有模板管道 A 可以发布到共享资源。因此,我可以在模板管道 A 中为共享的 azure 资源创建相关保护——因此我限制了开发人员 X 如何发布到我的共享 azure 资源。
- 这有意义吗?可行吗?
- A 中的管道部分不能由 X 中的开发人员编辑?
- A 中的服务连接不会传播出去,所以 X 中的开发人员可以以不适当的方式使用它?
更新
上述解决方案似乎不可行,因为管道模板是在源分支范围内执行的。
建议的解决方案
由于这些问题,我从上述建议中看到的好处似乎是不可能的。但是,可以利用管道触发器作为一种可行的解决方案。然而,这导致了一个新问题。当开发人员 Y 在 Y 的存储库中触发管道并成功时。然后在 MAIN 存储库中进行触发器,并且 MAIN 中的管道失败,例如,因为来自 Y 的工件引入了一个问题。开发人员 Y 如何获得有关 MAIN 管道中问题的通知?
解决方案
这是我的解决方案,在同一个 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”
推荐阅读
- javascript - 如何遍历存储在本地存储 JavaScript 中的数组?
- python - 键错误:
在多标签 U-net 中 - vbscript - 在经典 ASP 中使用输出参数进行 DLL 调用
- java - 不使用 FXML 时如何修复 Java 错误?
- javascript - 如何缩小 Laravel .js 和 .css 文件
- github - Azure Pipelines 拒绝创建 GitHub 版本
- python - 如何在 django 中提供动态文件?
- python - 如何在 matplotlib 的绘图曲线中设置黑暗?
- r - 在 R 中处理零的同时对数转换(受其他约束)
- go - 通过局域网接收文件时将文件保存到网络文件夹时出现问题 - Golang