如何限制Azure DevOps存储库中的开发人员对build.yml文件的访问

在Azure DevOps中,我们使用经典方式创建了构建和发布管道,现在我们计划将其转换为yaml文件。

但是在yaml方法中,似乎只能将代码放在存储库的根目录下,在该目录下我们希望将构建yaml文件保存在单独的存储库中,开发人员将无法访问该存储库。

如何实现?

lk_8715 回答:如何限制Azure DevOps存储库中的开发人员对build.yml文件的访问

您可以使用templates,仅将引用模板的最小yalm放入主仓库中,该模板具有所有步骤,该模板在另一个仓库中退出。

例如,您的主仓库yaml

resources:
  repositories:
    - repository: templates
      type: git
      name: Contoso/BuildTemplates

jobs:
- template: common.yml@templates  # Template reference

在回购中:Contoso / BuildTemplates放入完整的yaml

# Repo: Contoso/BuildTemplates
# File: common.yml
parameters:
  vmImage: 'ubuntu 16.04'

jobs:
- job: Build
  pool:
    vmImage: ${{ parameters.vmImage }}
  steps:
  - script: npm install
  - script: npm test

限制对第二个存储库的访问(除非代理管道用户)。

阅读here有关资源的更多信息。

,

您不必将YAML文件保留在存储库的根目录中;我们的文件位于一个专用的子文件夹中:

Example of a YAML pipeline file in a subfolder

这很关键,因为这意味着我们可以添加PR策略,该策略限制谁可以批准对任何管道YAML文件的更改。

,

我同意一种解决方案可能是@Shayki Abramczyk提出的解决方案

但是要在专用存储库中具有独立的* .yml,可以在使用“ Git凭据”访问包含要通过管道构建的文件的其他存储库时使用“ git clone”。

如果专用于* .yml的存储库位于同一Azure Devops项目中,则发行版本定义应该没有任何问题。

请按照以下说明查看适用于我们的示例* .yml:

pool:
  vmImage: 'your-preferred-image'

variables:
  solution: '$(Agent.BuildDirectory)/**/YourSolution.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Debug'
  urlWithCreds: 'https://YourUser:YourPassword@dev.azure.com/YourOrganization/YourProject/
    _git/YourOtherRepository'

steps:
- task: CmdLine@2
  inputs:
    script: |
      git --version
      git clone --quiet $(urlWithCreds)
      git checkout master

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: 'your build args'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
本文链接:https://www.f2er.com/3168067.html

大家都在问