Home > other >  YAML Pipeline Branching Git Error, saying no Git repo found
YAML Pipeline Branching Git Error, saying no Git repo found

Time:12-14

Trying to do a multistage yaml pipeline and running into an issue with Git. My pipeline is starting off with creating a new branch based on the build id, snippet of the code below:

$exportBranchName = "PipelineRun_BuildId$(Build.BuildId)"
cd $(Build.SourcesDirectory)
git config user.email "[email protected]"
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"

Sample code below that's pushing the changes:

git fetch $exportBranchName = "PipelineRun_BuildId$(Build.BuildId)"
cd $(Build.SourcesDirectory)
git config user.email "[email protected]"
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.

CodePudding user response:

From the error information Not a git repository ,it means that there are no files managed by your git in this directory.

You should switch the working folder to the repository folder by the command cd $(Build.SourcesDirectory) firstly.

From your sample code, you use git fetch command to download objects but not folder managed under git, so you should change the order:

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

CodePudding user response:

Use the .\ before the Dir name or use the full path.

  • Related