1

Having the following error:

remote: TF401019: The Git repository with name or identifier MyRepo does not exist or you do not have permissions for the operation you are attempting. fatal: repository 'https://dev.azure.com/MyCompany/MyProject/_git/MyRepo/' not found

Pipeline:

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:[email protected]/MyCompany/MyProject/_git/MyRepo
            }
            Set-Location $path -PassThru
            Git pull
          failOnStderr: true
          showWarnings: true
          workingDirectory:  $(Build.SourcesDirectory)

As you can see, I have also set the security settings: Security Settings in Repository

Any ideas?

4
  • 1
    In general, you'll want to avoid writing the Git binary as Git. While that may happen to work on Windows, it absolutely will not work on Unix or under WSL. Commented Dec 11, 2022 at 22:13
  • 1
    Why are you trying to check out a repository via the CLI instead of adding a repository resource and using the standard checkout task? Commented Dec 11, 2022 at 23:05
  • Did the answer posted on the ticket help you? If it helps. just as a remind of accepting an answer. Thanks for your kindness :-) Commented Dec 21, 2022 at 7:49
  • @EvelynChen-MSFT yes, thank you. I will use a different approach Commented Dec 28, 2022 at 15:02

1 Answer 1

1

Please note that there are two service accounts, one is the collection level account (Project Collection Build Service (xxxxx)) and another is project level account ({ProjectName} Build Service (xxx) ). If you have enabled the Limit job authorization scope to current project for non-release pipelines setting, you are using the project level account. Please make sure the corresponding build service account has the required permission.

At the same time, please check if you have enabled Protect access to repositories in YAML pipelines.

With this option enabled, you can reduce the scope of access for all pipelines to only Azure DevOps repositories explicitly referenced by a checkout step or a uses statement in the pipeline job that uses that repository.

If you do, you could try disabling the setting Protect access to repositories in YAML pipelines in Project settings->Pipelines->Settings to see if it works. enter image description here For your reference, you could find more details in this official doc: Access repositories, artifacts, and other resources.

By the way, you could also click the button Gnerate Git Credential when you trying to clone the repo. enter image description here

And use the username and the password in the following script to clone the repo:

git clone https://username:[email protected]/MyOrganization/MyProject/_git/MyRepoName

And you could also consider simply using the checkout step.

If you want to checkout multiple repositories, you could consider following the steps in this official doc: Check out multiple repositories in your pipeline.

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

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- checkout: self
- checkout: MyAzureReposGitRepository
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.