通过命令行从Azure Devops下载应用程序 [英] Download an application from Azure Devops via command line

查看:57
本文介绍了通过命令行从Azure Devops下载应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过命令行(例如使用Powershell)从azure devops存储库中定期下载应用程序,但是我不能为此使用git插件.除了git以外,还有其他方法吗?

I would like to download an application from azure devops repository via command line (like using powershell) peridiocally but i can not use git plugin for that. IS there any way besides git to do that?

推荐答案

您可以使用Azure DevOps Rest API从Git存储库下载文件-

You can download files from Git repository with Azure DevOps Rest API - Items - Get (without git plugin).

https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/items?path={path}&api-version=5.0-preview.1

如果添加参数 download (例如:?path = {path}& download = true ),则文件将被下载.

If you add the parameter download (for example: ?path={path}&download=true) the file will be downloaded.

因此您可以使用PowerShell脚本获取文件:

So you can get the file with PowerShell script:

Param(
   [string]$organization= "<Organization-NAME>",
   [string]$projectName = "<PROJECT-NAME>",
   [string]$repoId= "<Repository-ID>",
   [string]$appPath= "<Application-Path>",
   [string]$user = "",
   [string]$token = "<PERSONAL-ACCESS-TOKEN>"
)

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

$uri = "https://dev.azure.com/$($organization)/$($project)/_apis/git/repositories/$($repoId)/items?path=$($appPath)&download=true&api-version=5.0-preview.1"

$result = Invoke-RestMethod -Uri $uri -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

这篇关于通过命令行从Azure Devops下载应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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