Azure DevOps 管道,git 身份验证仅适用于 -c http.extraheader

问题描述 投票:0回答:1

我需要在 Azure DevOps 管道中克隆存储库。当我提供与

System.AccessToken
内联的
git clone
时,身份验证有效。但我不想提供此标头,而是对其进行配置,以便凭证管理器可以读取该标头。最终我想运行
terraform init
命令来克隆存储库,而无需内联提供标头。

简单来说,以下代码行有效:

  • git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" 
    但如果没有
    http.extraheader
    ,它就不起作用。

补充说明:

  • 我在管道中设置了
    persistCredentials: true
  • 我想克隆管道最初可以克隆的相同存储库以获取 yml 文件。
  • 构建服务具有对存储库的读取访问权限。

如有任何帮助,我们将不胜感激。

git authentication azure-devops azure-pipelines
1个回答
0
投票

有多种方法可以检查管道中的多个存储库 - Azure Pipelines | Microsoft Learn,我们不需要添加标题。这是一个示例供您参考。

请注意,如果您要在脚本中使用

git clone
命令在 YAML 管道中签出 non-self 存储库(在我的示例中为
RepoC
),请不要忘记禁用
Protect access to repositories in YAML pipelines

pool:
  vmImage: windows-latest

resources:
  repositories:
  - repository: A
    name: RepoA
    type: git

steps:
- checkout: self # TestRepo
- checkout: A
  path: RepoA
  displayName: Checkout RepoA
- checkout: git:///$(TheProjectName)/RepoB
  path: RepoB
  displayName: Checkout RepoB
- powershell: |
    Write-Host "Agent.BuildDirectory - $(Agent.BuildDirectory)"
    git clone https://$(AzureDevOpsOrgName):$(System.AccessToken)@dev.azure.com/$(AzureDevOpsOrgName)/$(TheProjectName)/_git/RepoC
    tree /F /A
  displayName: Checkout RepoC
  workingDirectory: $(Agent.BuildDirectory)

© www.soinside.com 2019 - 2024. All rights reserved.