接收“致命:不是git存储库(或任何父目录):. git"在使用pat使用天蓝色powershell将代码推送到bitbucket的同时 [英] Receiving "fatal: not a git repository (or any of the parent directories): .git" while using pat to push code into bitbucket using azure powershell

查看:37
本文介绍了接收“致命:不是git存储库(或任何父目录):. git"在使用pat使用天蓝色powershell将代码推送到bitbucket的同时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Azure PowerShell脚本,该脚本将使用JSON文件,该文件具有我所有SQL脚本的位置和Migrationflag列(保留要执行/将要执行的位置),并执行所有脚本序列.执行后,该标志将更改为"N",更新后的JSON文件应上传到bitbucket.现在,我坚持致命:不是git存储库(或任何父目录):. git";尝试推送时出错.

我已经创建了一个使用用户名:santhoshsreshta的pat令牌和服务连接,下面是要推送的代码.

  $ v_JSON =获取内容'$(system.defaultworkingdirectory)\ locationToBuild \ BuildOrder.json'-原始|ConvertFrom-Json$ v_JSON |排序对象-属性订单编号|哪里对象{$ _.MigratedFlag -like'Y'} |每次{$脚本= $ _.位置写主机执行脚本:$脚本";调用Sqlcmd -ServerInstance"myservername"-数据库$(数据库)-用户名$(testauto_username)-密码$(testauto_password)-InputFile $(system.defaultworkingdirectory)\ $ Script$ _.MigratedFlag ='N'}$ v_JSON |ConvertTo-Json-深度32 |设置内容'$ {system.defaultworkingdirectory)\ locationToBuild \ BuildOrder.json'$ MyPat ='mypatcode'git push https://mygitusername:$MyPat@bitbucket.org/xyz/abcd.git 

得到错误,"## [错误]致命:不是git存储库(或任何父目录):. git";但是在发布git clone https://mygitusername:$MyPat@bitbucket.org/xyz/abcd.git时-获取无效的用户名/密码错误.我相信我们不应该再克隆,因为我的管道获取源任务会克隆它并放入自托管代理中.

这是我的git网址:https://mygitusername@bitbucket.org/xyz/abcd.git

一吨,DevOps,PowerShell新手在这里.

解决方案

在使用pat将代码通过天蓝色Powershell推送到bitbucket时,收到致命:不是git存储库(或任何父目录):. git"的消息

那是因为我们正在使用git功能,但是不在git管理的文件夹中.

当我们直接使用Azure Powershell任务时,默认工作文件夹应为:

  PS C:\ Users \< Username> 

很显然,此目录中没有任何由git管理的文件.这就是为什么您收到错误 Not a git repository .

的原因.

因此,要解决此问题,我们只需要通过以下命令将工作文件夹切换到repo文件夹:

cd $(System.DefaultWorkingDirectory)

检查使用

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)\locationToBuild\BuildOrder.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)\locationToBuild\BuildOrder.json'
                
$MyPat = 'mypatcode'
git push https://mygitusername:$MyPat@bitbucket.org/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:$MyPat@bitbucket.org/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://mygitusername@bitbucket.org/xyz/abcd.git

Thanks a ton, A DevOps, PowerShell newbie here.

解决方案

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:password@bitbucket.org/Lsgqazwsx/leotest.git HEAD:master

这篇关于接收“致命:不是git存储库(或任何父目录):. git"在使用pat使用天蓝色powershell将代码推送到bitbucket的同时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆