5
votes

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
5
Did you enable "Allow access to oauth token" in your build?Daniel Mann
Yes, I did, I also tried both personal access token (string64 encoded and not) and System.AccessToken valuesTaras
If you run this command in a command prompt, you have to escape the percentage sign for the space as %%20. So, try git clone https://%SYSTEM_ACCESSTOKEN%@dev.azure.com/mycompany/My%%20Test/_git/whateverAxel Habermaier

5 Answers

3
votes

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}'
1
votes

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

0
votes

Can you try to change your Command Line task to something like this one?

git clone --single-branch --branch $(branchName) https://$(gitUserName):$(gitPassword)@dev.azure.com/myCompany/My%20Test%20Project/_git

Where $(gitUserName) and $(gitPassword) configured as Alternate git credentials in your Azure DevOps account.

Also wanted to ask about ending of git repository URL: ".../_git/Service.Azure.Core", you are trying to specify which folder to clone or maybe working directory? You can also try your previous code without that ending, just https://dev.azure.com/myCompany/My%20Test%20Project/_git

0
votes

I tried this from Powershell task and it worked Its very simple just use

- powershell: |
   git config user.email "$(Build.RequestedForEmail)"
   git config user.name "$(Build.RequestedFor)"
   git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)"  clone  https://<org_Name>.visualstudio.com/<project_name>/_git/<repository_name>;
  displayName: "<your task display name>"
0
votes

This will happen when your path has space characters in it.

The workaround for this is to not use %20 in your URL and use actual space characters instead. Since your URL now has space characters, also make sure that your URL is wrapped inside double quotes.

So your

git clone https://dev.azure.com/myCompany/My%20Test%20Project/_git/Service.Azure.Core/

should be

git clone "https://dev.azure.com/myCompany/My Test Project/_git/Service.Azure.Core/"