简体   繁体   English

YAML 管道分支 Git 错误,说没有找到 Git 存储库

[英]YAML Pipeline Branching Git Error, saying no Git repo found

Trying to do a multistage yaml pipeline and running into an issue with Git.尝试执行多级 yaml 管道并遇到 Git 问题。 My pipeline is starting off with creating a new branch based on the build id, snippet of the code below:我的管道从基于构建 ID 创建一个新分支开始,下面是代码片段:

$exportBranchName = "PipelineRun_BuildId$(Build.BuildId)"
cd $(Build.SourcesDirectory)
git config user.email "pipeline@devops.com"
git config user.name "Pipeline"
git checkout -b $exportBranchName
git push -u origin $exportBranchName

I'm then calling two separate template files that do slightly different things, however the ending in the templated files to push the changes into the above branch is the same in both.然后我调用两个单独的模板文件,它们做的事情略有不同,但是模板文件中将更改推送到上述分支的结尾在两者中是相同的。

Strangely the second template file works, but the first fails with the error "fatal: not a git repository (or any of the parent directories): .git"奇怪的是,第二个模板文件有效,但第一个失败并出现错误“fatal: not a git repository (or any of the parent directories): .git”

Sample code below that's pushing the changes:下面的示例代码正在推动更改:

git fetch $exportBranchName = "PipelineRun_BuildId$(Build.BuildId)" git fetch $exportBranchName = "PipelineRun_BuildId$(Build.BuildId)"
cd $(Build.SourcesDirectory)
git config user.email "pipeline@devops.com"
git config global user.name "Pipeline"
git checkout $exportBranchName
git add --all
git commit -m "Comiting ${{ parameters.solutionName }} to branch PipelineRun_BuildId$(Build.BuildId)"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push --set-upstream origin $exportBranchName

Just wondering if anyone has an idea to what's causing the first to fail, but not the second?只是想知道是否有人知道是什么导致第一个失败,而不是第二个?


Tried enabling debug on the pipeline, but the logs are showing no obvious changes between the two templated files.

From the error information Not a git repository ,it means that there are no files managed by your git in this directory.从错误信息Not a git repository来看,说明这个目录下没有你的git管理的文件。

You should switch the working folder to the repository folder by the command cd $(Build.SourcesDirectory) firstly.您应该首先通过命令cd $(Build.SourcesDirectory)将工作文件夹切换到存储库文件夹。

From your sample code, you use git fetch command to download objects but not folder managed under git, so you should change the order:从您的示例代码中,您使用git fetch命令下载对象而不是在 git 下管理的文件夹,因此您应该更改顺序:

 cd $(Build.SourcesDirectory)
 git fetch $exportBranchName = "PipelineRun_BuildId$(Build.BuildId)"

update更新

Another possible cause of this issue: multiple repositories are checked out in your stage.此问题的另一个可能原因:在您的阶段检出多个存储库。 You can make sure how many repositories you have checked out in your stage.您可以确定在您的阶段检出了多少存储库。 If you check out multiple repositories, use below command to go into repo folder:如果您签出多个存储库,请使用以下命令进入 repo 文件夹:

cd $(Build.SourcesDirectory)/reponame

Use the.\ before the Dir name or use the full path.在 Dir 名称前使用 .\ 或使用完整路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM