簡體   English   中英

Azure devops 服務連接和中心管道

[英]Azure devops service connection and central pipeline

我需要讓多個團隊訪問 azure 中的共享資源。因此我想限制人們如何發布對共享資源的更改。

這個想法是根據此文檔將服務連接的使用限制到特定管道。 但是,如果管道存儲在他們自己的倉庫中,開發人員可以更改它。 這不會給我足夠的控制權。 因此,我發現可以使用來自中央倉庫的模板 使用共享存儲庫,是否會允許我僅針對模板建立服務連接?

因此,我如何想象執行上述操作是我需要為我的 BuildTemplates Repo 授予項目 X 服務連接。 但這基本上只是訪問存儲庫並能夠使用共享模板。 然后在 BuildTemplates 存儲庫中,我可以為我的模板 A 建立服務連接。

現在項目 X 中的開發人員使用她自己的服務連接為她的資源創建她的管道的部署和配置。 然后她從BuildTemplates Repo繼承了一個模板,並為模板A傳遞了相關參數。

由於作用域服務連接,她無法更改模板管道 A,並且只有模板管道 A 可以發布到共享資源。 因此,我可以在模板管道 A 中為共享的 azure 資源創建相關的守衛——因此我限制了開發人員 X 如何發布到我的共享的 azure 資源。

  • 這有意義嗎?可行嗎?
  • A 中的管道部分不能由 X 中的開發人員編輯?
  • A 中的服務連接不會傳播出去,因此 X 中的開發人員可以以不適當的方式使用它?

更新

上述解決方案似乎不可行,因為管道模板是在源分支 scope 中執行的。

建議的解決方案

由於這些問題,我從上述建議中看到的好處似乎是不可能的。 但是,可以利用管道觸發器作為一種可行的解決方案。 然而,這會導致一個新問題。 當 Y 的存儲庫中的開發人員 Y 觸發管道並成功時。 然后在 MAIN 存儲庫中創建一個觸發器,並且 MAIN 中的管道失敗,例如,因為來自 Y 的工件引入了一個問題。 開發人員 Y 如何獲得有關 MAIN 管道中問題的通知?

這是我的解決方案,在同一個 Azure 組織中,我們可以創建一個 Azure 項目,然后創建一個 repo 來保存通用管道模板。 其他 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/模板-pipeline.yml

由於管道的內聯腳本有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)"

備注:Organization Setting - Settings - Disable Limit job authorization scope to current project for release pipelines

Organization Setting - Settings - Limit job authorization scope to current project 對於非發布管道

還要檢查項目設置中的一些選項。

在此處輸入圖像描述

所以普通用戶只能訪問自己的 repo,不能訪問 DevOps 項目,DevOps 所有者只能編輯模板管道。

對於通知問題,我使用 Email 擴展名“rvo.SendEmailTask.send-email-build-task.SendEmail@1”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM