Stack Overflow Asked on December 9, 2021
I am writing an Azure PowerShell script that will consume the JSON file which has the location of all my SQL scripts and Migrationflag column (which holds to execute/to be executed) and execute all the sequence of scripts.
upon execution, the flag will change to ‘N’ and the updated JSON file should be uploaded to bitbucket.
Now, I am stuck with "fatal: not a git repository (or any of the parent directories): .git" error while trying to push.
I’ve created a pat token and service connection with username: santhoshsreshta and below is the code to push.
$v_JSON = Get-Content '$(system.defaultworkingdirectory)locationToBuildBuildOrder.json' -Raw | ConvertFrom-Json
$v_JSON | Sort-Object -Property OrderNo | Where-Object {$_.MigratedFlag -like 'Y'} | ForEach {
$Script = $_.Location
Write-Host "Executing Script: $Script"
Invoke-Sqlcmd -ServerInstance "myservername" -Database $(database) -Username $(testauto_username) -Password $(testauto_password) -InputFile $(system.defaultworkingdirectory)$Script
$_.MigratedFlag = 'N'
}
$v_JSON | ConvertTo-Json -depth 32| set-content '$(system.defaultworkingdirectory)locationToBuildBuildOrder.json'
$MyPat = 'mypatcode'
git push https://mygitusername:[email protected]/xyz/abcd.git
getting the error,"##[error]fatal: Not a git repository (or any of the parent directories): .git"
but when issuing git clone https://mygitusername:[email protected]/xyz/abcd.git — getting invalid username/password error.
I believe we should not clone again as my pipelines get sources task will clone it and puts in a self-hosted agent.
this is my git url: https://[email protected]/xyz/abcd.git
Thanks a ton,
A DevOps, PowerShell newbie here.
It means that there is no local .git & you need to do the below first:
git init
git commit -m "first commit"
git branch -M main
git remote add origin https://your-repo-url
git push -u origin main
I just copied the below from GitHub page & it works for Azure Repos :-) further showing the power & advantage of companies following universal standards
Answered by Anand on December 9, 2021
Receiving “fatal: not a git repository (or any of the parent directories): .git” while using pat to push code into bitbucket using azure powershell
That because we are using git feature, but we are not in the folder managed by git.
When we use Azure powershell task directly, the default work folder should be:
PS C:Users<Username>
Obviously, there are no files managed by our git in this directory. That the reason why you get the error Not a git repository
.
So, to resolve this issue, we just need to switch the working folder to the repo folder by the command:
cd $(System.DefaultWorkingDirectory)
Check the Use predefined variables and this thread for some details.
Update:
The test sample:
cd $(System.DefaultWorkingDirectory)
cd leotest
echo 123>Test.txt
git add Test.txt
git commit -m "Add a test file"
git push https://Username:[email protected]/Lsgqazwsx/leotest.git HEAD:master
Answered by Leo Liu-MSFT on December 9, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP