TFS在线2017通过PowerShell上传文件

问题描述 投票:-3回答:1

我有一个2017年在线TFS试用版,我试图找到一种方法来使用powershell命令上传文件。我尝试使用包装的api命令安装一些相关的模块,但它们都没有类似的东西。

有什么建议吗?here are actually the two commands i am trying to execute through ps

tfs tfs2017
1个回答
0
投票

你为什么要这样做?通过门户网站的操作更方便和友好。

无论您如何尝试使用REST API。

创建一个文件夹:(在下面的示例中,在test0232下创建文件夹$/0522TFVCScrum/

Param(
   [string]$vsoAccount = "YourInstance",
   [string]$keepForever = "true",
   [string]$user = "[email protected]",
   [string]$token = "PAT or Password here"
)

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

function CreateJsonBody
{
    $value = @"
{"changes":[{"changeType":1,"item":{"path":"$/0522TFVCScrum/test0232","isFolder":true}}],"comment":"Added folder test0232"}
"@
 return $value
}

$json = CreateJsonBody

$uri = "https://$($vsoAccount).visualstudio.com/_apis/tfvc/changesets?api-version=4.1-preview.3"
$result = Invoke-RestMethod -Uri $uri -Method Post -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

Write-host $result

使用下面的body创建一个文件:(只需替换上面脚本中的Jsonbody,在此示例中创建的0229test.ps1

{"changes":[{"changeType":1,"item":{"path":"$/0522TFVCScrum/0229test.ps1","contentMetadata":{"encoding":65001}},"newContent":{"content":"test0229","contentType":0}}],"comment":"Added file 0229test.ps1"}

上传文件:

无法找到直接使用REST API上传文件的方法,但是您可以先尝试copy files到工作区,然后使用Add command在源代码管理中添加文件,然后使用Checkin command检入文件。

下载为Zip:

您可以使用工具跟踪API,然后您可以获得如下所示的URL:

https://{your account}.visualstudio.com/b3cbc52a-22f6-4de9-ae78-b2b305365ff8/_api/_versioncontrol/itemContentZipped?repositoryId=&path=%24%2F0522TFVCScrum%2Ftest0228&version=T&__v=5

然后,您可以尝试在脚本中使用该URL下载。

© www.soinside.com 2019 - 2024. All rights reserved.