gitauthenticationazure-devopsazure-pipelines

Azure Devops pipeline, git authentication only works with -c http.extraheader


I need to clone repositories in an Azure DevOps pipeline. When I provide the System.AccessToken inline with git clone, authentication works. But I don't want to provide this header but rather configure it so that credential manager can read that. Eventually I want to run terraform init command that will clone repositories without header provided inline.

Simply, the following line works:

Additional notes:

Any help would be appreciated.


Solution

  • There are several ways to Check out multiple repositories in your pipeline - Azure Pipelines | Microsoft Learn and we don't need to add headers. Here is a sample for your reference.

    Please note that, if you would use git clone command in a script to checkout a non-self repo (RepoC in my sample) in a YAML pipeline, please don't forget to disable Protect access to repositories in YAML pipelines.

    enter image description here

    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)
    

    enter image description here