Reputation: 340
Short Version
When a build pipeline is triggered, one of the build pipeline task will get the latest files and it has to be added/updated in the git repository of current running pipeline. I tried to do it by using command line task but its failing as not git repository
fatal: not a git repository (or any of the parent directories): .git
Long Version
I m tried to achieve solution pack and unpack process for dynamics 365 instance. So the build pipeline have the following tasks
Export solution from Dynamics 365 and store it in $(build.binariesdirectory)
Unpack the solution zip file and store in $(Build.Repository.LocalPath) i.e., adding/updating existing files
Command line task to commit and push the files to current pipeline repository
ECHO "Setting git config..."
git config --global user.email "[email protected]"
git config --global user.name "Admin"
ECHO "CHECK GIT STATUS..."
git status
ECHO "GIT ADD..."
git add -A
ECHO "CHECK GIT STATUS..."
git status
ECHO "Commiting the changes..."
git commit -m "Latest Customizations updated"
ECHO "Pushing the changes..."
git push -u origin master
ECHO "Customization Committed Successfully"
Updated
If a pipeline is created with 2 command line task i.e. one to create a random file in the Build.Sourcedirectory
and another to commit the changes, then the git commit and push commands are working.
But if we add other tasks (such as unzip files in Build.Sourcedirectory
directory) before the command line task then getting error as not a repository.
If you see the below screenshot, in the checkout phase the git repo is cloned to D:\a\1\s
And below screenshot is from command line task, where the current working directory is same as the checkout task (i.e., D:\a\1\s
) and we can see that the ".git" folder is present so the current directory has local repository in it, but still getting error as fatal: not a git repository
Am I missing anything here?
Upvotes: 6
Views: 19999
Reputation: 1
I know it has been a couple of years but for anyone who's having trouble with this is because when you unpack the solution to $(Build.Sourcedirectory)
, it overwrites the root directory of the repo and causing the fatal: not a git repository
issue.
To fix the issue, unpack the solution to a sub folder such as $(Build.SourcesDirectory)\$(solutionName)
where $(solutionName)
is the pipeline variable.
Upvotes: 0
Reputation: 30372
By default the source files are checked out to the Build.SourcesDirectory
(e.g : Directory: D:\a\1\s
), it can be considered as a temporary git repository.
According to the error message, it appears that the working directory of the command line task is not under the Build.SourcesDirectory
and you did't git checkout
again to that working directory.
So, please try unpack the solution zip file and store in Build.SourcesDirectory
, then run below Command line to push the commits (it works for me):
ECHO "Setting git config..."
git config --global user.email "[email protected]"
git config --global user.name "Admin"
ECHO "CHECK GIT STATUS..."
git status
git checkout -b master
ECHO "GIT ADD..."
git add -A
ECHO "CHECK GIT STATUS..."
git status
ECHO "Commiting the changes..."
git commit -m "Latest Customizations updated"
ECHO "Pushing the changes..."
git push -u origin master
ECHO "Customization Committed Successfully"
Please note that you need to Grant version control permissions to the build service and enable Allow scripts to access the system token.
Upvotes: 13