YAML Pipeline branches Git Error,没有找到Git repo



尝试做多级yaml管道,遇到Git问题。我的管道首先基于构建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

然后我调用两个独立的模板文件,它们做的事情略有不同,但是在模板文件中,将更改推入上述分支的结尾是相同的。

奇怪的是,第二个模板文件可以正常工作,但是第一个模板文件失败了,并报错"fatal: not a git repository(或任何父目录):.git">

下面是推动更改的示例代码:

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

只是想知道是否有人知道是什么原因导致第一个失败,而不是第二个?


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

在Dir名称前使用。或使用完整路径。

从错误信息Not a git repository来看,这意味着在这个目录下没有git管理的文件。

您应该首先通过命令cd $(Build.SourcesDirectory)将工作文件夹切换到存储库文件夹。

在您的示例代码中,您使用git fetch命令下载对象,而不是git下管理的文件夹,因此您应该更改顺序:

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

此问题的另一个可能原因是:在您的阶段签出了多个存储库。您可以确定在您的阶段中签出了多少存储库。如果你签出了多个仓库,使用下面的命令进入repo文件夹:

cd $(Build.SourcesDirectory)/reponame

最新更新