Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot clone git repository in command line script task in Azure DevOps Pipelines

I created azure devops pipeline where I need to download code from another git repository. As per recommended solution I've read somewhere, I added a command line script task with git clone command. Unfortunatelly this doesn't work.

The error that I get is: remote: TF200016: The following project does not exist: My0Test0Project. Verify that the name of the project is correct and that the project exists on the specified Azure DevOps Server. fatal: repository 'https://dev.azure.com/myCompany/My0Test0Project/_git/Service.Azure.Core/' not found

My project in Azure has spaces, maybe there is a bug in azure related to that? Does anybody knows any workarounds?

This is some code that I have tried already:

git -c http.extraheader="AUTHORIZATION: Basic bXl1c2VyOmxtNjRpYTYzb283bW1iYXp1bnpzMml2eWxzbXZoZXE2azR1b3V2bXdzbnl5b3R5YWlnY2E=" clone https://dev.azure.com/myCompany/My%20Test%20Project/_git/Service.Azure.Core
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" clone https://dev.azure.com/myCompany/My%20Test%20Project/_git/Service.Azure.Core
git clone https://oauth:lm64ia63oo7mmbazunzs2ivylsmvheq6k4uouvmwsnyyotyaigca@dev.azure.com/myCompany/My%20Test%20Project/_git/Service.Azure.Core
git clone https://test:$(System.AccessToken)@dev.azure.com/myCompany/My%20Test%20Project/_git/Service.Azure.Core
like image 432
Taras Avatar asked Apr 24 '19 15:04

Taras


People also ask

How do I clone a Git repo in Visual Studio?

Verify the location of the cloned repo on your PC and select Clone. If you aren't using Azure Repos, you can still clone your repo in Team Explorer and work with your code in Visual Studio. In Team Explorer, open the Connect view, as explained above. Select Clone under Local Git Repositories and enter the URL for your Git repo.

Where can I find the Azure DevOps repository clone url?

If you're using Azure Repos, Azure DevOps Server 2019, or Team Foundation Server, you can find this clone URL in the web portal. From your web browser, open the team project for your Azure DevOps organization and choose Repos, then Files. Select Clone in the upper right. If you need to clone a GitHub repo,...

How do I give permission to a git repository on azure?

In order to give it permission to clone you can either add your username and password or add a personal access token (PAT) to the url in the gitmodules file in your repo on Azure devops. You need to change the url to https://username:[email protected]/organization/project/_git/repo or https://[email protected]/organization/project/_git/repo

How do I clone a git repository in Team Explorer?

In Team Explorer, open the Connect view, as explained above. Select Clone under Local Git Repositories and enter the URL for your Git repo. Your team or Git hosting provider gives you this URL. Select a folder where you want your cloned repo. Select Clone to clone the repo.


2 Answers

The reason is because you need to add the system access token so that Azure can have access to the external repo. (your credentials need access to that repo)

NOTE:

I wrapped my URL in quotes to escape the % signs in the URL string because Powershell treats those as variables otherwise.

- powershell: |
    git clone -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" "https://{YOUR PIPELINE URL}"
    displayName: '{YOUR PIPELINE NAME}'
like image 190
Blake Linnell Avatar answered Sep 28 '22 05:09

Blake Linnell


I had the same issue from a bash script and solved it by escaping the % character with %%.

So, you can use this :

git clone https://test:$(System.AccessToken)@dev.azure.com/myCompany/My%%20Test%%20Project/_git/Service.Azure.Core

like image 38
Nicos99 Avatar answered Sep 28 '22 06:09

Nicos99