VitS部署任务在git命令上失败

VitS部署任务在git命令上失败

本文介绍了VitS部署任务在git命令上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个简单的构建/部署任务,其中部分任务涉及克隆外部git存储库。我的场景是我的TFS git存储库是作为普通的Visual Studio解决方案构建而构建的,并且部分输出(我的工件)将是
提交给外部git存储库。现在我有一个非常基本的PowerShell脚本,它将git存储库url与用户名和密码一起使用,并使用它来克隆存储库,但是在克隆存储库时构建过程失败。
日志没有说明它失败的原因,但看起来它可能是git命令它不喜欢(即使它继续克隆并检查头部)。

所以我的问题是 - 是否有正确/错误/更好的方法从VSTS构建/部署任务中的powershell脚本执行git命令?

I'm trying to build a simple build/deploy task where part of the task involves cloning an external git repository. My scenario is that my TFS git repository is built as a normal Visual Studio solution build, and part of the output (my artifacts) will be committed to an external git repository. Right now I have a very basic powershell script that takes the git repository url along with username and password and uses that in order to clone the repository, but the build process fails when cloning the repository. The logs doesn't indicate why its failing, but it looks like it might be git command that it doesn't like (even though it continues with the clone and checking out the head).
So my question is - is there a right/wrong/better way of doing git commands from a powershell script in a VSTS build/deploy task?

这是PowerShell的一个示例(在$ curentdirectory中执行)

Here is an example of the powershell (executing in $curentdirectory)

[cmdletbinding()] param ( [String] [Parameter(Mandatory = $true)] $cloneUrl, [String] [Parameter(Mandatory = $true)] $userName, [String] [Parameter(Mandatory = $true)] $password ) Write-Verbose "Entering script CloneRepository.ps1" Write-Verbose "Parameter Values" foreach($key in $PSBoundParameters.Keys) { Write-Verbose ($key + ' = ' + $PSBoundParameters[$key]) } if(!$cloneUrl) { throw ("Clone Url parameter must be set.") } import-module "Microsoft.TeamFoundation.DistributedTask.Task.Common" [Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null $UsernameEncoded = [System.Web.HttpUtility]::UrlEncode($userName) $PasswordEncoded = [System.Web.HttpUtility]::UrlEncode($password) $cloneUri = New-Object System.Uri $cloneUrl $newRemoteUrlBuilder = New-Object System.UriBuilder($cloneUri) $newRemoteUrlBuilder.UserName = $UsernameEncoded $newRemoteUrlBuilder.Password = $PasswordEncoded

#Do这里的实际git clone
git clone $ newRemoteUrlBuilder.ToString()

Write-Verbose" Leaving script CloneRepository。 ps1"

#Do the actual git clone heregit clone $newRemoteUrlBuilder.ToString()Write-Verbose "Leaving script CloneRepository.ps1"

感谢任何输入!

谢谢,

Morten

推荐答案

感谢您在此处发帖。

我会请求您通过将system.prefergit设置为true来启用脚本来运行Git命令。

I would request you to enable the script to run the Git commands by setting system.prefergit to true .

请暂停以下链接以获取更多信息信息:

Please fallow the below link for more information:

https://www.visualstudio.com/en-us/docs/build/scripts/git-commands

如果这不起作用,我会请求您共享构建日志。

If this doesn’t work, I would request you share the build logs.

问候,

------------------- -------------------------------------------------- ----------------------------------

-------------------------------------------------------------------------------------------------------

如果帖子回答你的问题问题,请点击该帖子上的标记为答案并投票为有用。

If a post answers your question, please click Mark as Answer on that post and Vote as Helpful.


这篇关于VitS部署任务在git命令上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 11:28