簡體   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