繁体   English   中英

Azure DevOps:使用“git clone”的 Powershell 管道无法正常工作

[英]Azure DevOps: Pipeline with Powershell using "git clone" not working

出现以下错误:

远程:TF401019:名称或标识符为 MyRepo 的 Git 存储库不存在,或者您没有权限执行您正在尝试的操作。 致命:未找到存储库“https://dev.azure.com/MyCompany/MyProject/_git/MyRepo/”

管道:

stages:
 - stage: "Stage1"
   jobs:
    - job: MyJob
      displayName: 'MyJob'
      pool: 'MyWindowsSrv'
      steps:
      - checkout: self
        persistCredentials: true

      - task: PowerShell@2
        displayName: Some name...
        env:
          SYSTEM_ACCESSTOKEN: $(System.AccessToken)
        name: some_name
        inputs:
          targetType: 'inline'
          script: |
            $path = "C:\MyRepo"
            If(!(test-path -PathType container $path))
            {
                    Set-Location C:\ -PassThru
                    Git clone https://$env:SYSTEM_ACCESSTOKEN@dev.azure.com/MyCompany/MyProject/_git/MyRepo
            }
            Set-Location $path -PassThru
            Git pull
          failOnStderr: true
          showWarnings: true
          workingDirectory:  $(Build.SourcesDirectory)

如您所见,我还设置了安全设置: 存储库中的安全设置

有任何想法吗?

请注意,有两个服务帐户,一个是集合级帐户(Project Collection Build Service (xxxxx)),另一个是项目级帐户({ProjectName} Build Service (xxx) )。 如果您已启用将作业授权 scope 限制为非发布管道的当前项目设置,则您使用的是项目级别帐户。 请确保相应的构建服务帐户具有所需的权限。

同时请检查您是否在 YAML 管道中启用了保护对存储库的访问

启用此选项后,您可以将所有管道的 scope 访问权限减少到仅 Azure DevOps 存储库,这些存储库由使用该存储库的管道作业中的结帐步骤或使用语句明确引用。

如果这样做,您可以尝试在 Project settings->Pipelines->Settings 中禁用设置Protect access to repositories in YAML pipelines ,看看它是否有效。 在此处输入图像描述 作为参考,您可以在此官方文档中找到更多详细信息: Access repositories, artifacts, and other resources

顺便说一句,您还可以在尝试克隆存储库时单击按钮Gnerate Git Credential 在此处输入图像描述

并使用以下脚本中的用户名和密码克隆存储库:

git clone https://username:password@dev.azure.com/MyOrganization/MyProject/_git/MyRepoName

您也可以考虑简单地使用结帐步骤。

如果你想检出多个存储库,你可以考虑按照这个官方文档中的步骤操作: 检出管道中的多个存储库

resources:
  repositories:
  - repository: MyAzureReposGitRepository
    type: git
    name: OtherProject/MyAzureReposGitRepo

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- checkout: self
- checkout: MyAzureReposGitRepository

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM