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

爱⌒轻易说出口 提交于 2020-07-21 04:33:15

问题


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

回答1:


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



回答2:


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




回答3:


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>"



回答4:


I am having basically the same issue... only I am trying to clone from my OWN repo in MY project ... and the command does not complete or time out. This works just fine when i run it on the build server directly but NOT from the buidpipe.

cd $(system.defaultworkingdirectory)
md dependencies
cd dependencies
git clone http://somecrazy.devops.server.thing/3rdPartyNuget/Newtonsoft.Json/_git/Nancy-For-Newton
rename Nancy-For-Newton Nancy



回答5:


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/"



来源:https://stackoverflow.com/questions/55833316/cannot-clone-git-repository-in-command-line-script-task-in-azure-devops-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!