在 azure 管道 yml

时间:2021-04-21 18:05:17

标签: azure-devops azure-devops-pipelines

好吧,我有以下代码使用 azure Devops 中的模板文件:

resources:
  repositories:
    - repository: templates
      type: git
      name: "Framework Back-end/templates-devops"

extends:
  template: azure-pipelines-template.yml@templates

这很有效,从同一组织内的另一个项目下载 yml 文件。但在我的“azure-pipelines-template.yml”中,我正在尝试执行以下操作:

  - job: Deploy
    pool: ${{parameters.agent}}
    displayName: Deploy on Kubernetes
    dependsOn: Push
    condition: and(succeeded(), in(variables['Build.SourceBranchName'], 'master', 'main', 'qas', 'develop'))
    steps:
    - checkout: self
    - checkout: templates

但是我得到了错误:

remote: TF401019: The Git repository with name or identifier templates-devops does not exist or you do not have permissions for the operation you are attempting.
fatal: repository 'https://xx@xx/xxx/Framework%20Back-end/_git/templates-devops/' not found

我需要结帐,因为在其他步骤中,我需要使用“template-devops”存储库中存在的文件。我不明白为什么我的管道可以下载“azure-pipelines-template.yml”文件,但无法检出存储库。

已解决

是设置中的权限问题,我禁用标志:

将作业授权范围限制为引用的 Azure DevOps 存储库

将工作授权范围限制为非发布管道的当前项目

将工作授权范围限制为发布管道的当前项目

1 个答案:

答案 0 :(得分:0)

我创建了一个演示来重现您的环境,但它在我这边运行良好。结帐步骤运行良好。这是我的 yaml 文件和临时文件:

Main.yaml

resources:
  repositories:  
  - repository: templates
    type: git
    name: MyAgile TestPro/yaml

pool:
  name: 'default'


extends:
  template: azure-pipelines-template.yml@templates

Temp.yaml

  stages:
    - stage: 
      jobs:
        - job: Deploy
          steps:
            - checkout: self
            - checkout: templates
            - task: PowerShell@2
              inputs:
                targetType: 'inline'
                script: |
                  # Write your PowerShell commands here.
                  
                  Write-Host "Hello World MyAgileTestPro temp"

我的测试结果: enter image description here

目前,我们建议您可以检查您的帐户是否具有项目框架后端的项目管理员级别。并请检查您的项目是否有任何名称更改。