检查VSTS(VSTS API)中的先前版本信息 [英] Check previous build information in VSTS (VSTS API)

查看:60
本文介绍了检查VSTS(VSTS API)中的先前版本信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行VSTS构建期间可以访问以前的构建变量吗?例如,我可以获得上一个版本的$(Build.SourceVersion)或$(Build.QueuedBy)吗?

Are previous build variables accessible during execution of a VSTS build? For example, can I get $(Build.SourceVersion) or $(Build.QueuedBy) of the previous build?

我可以通过$(Build.SourceVersion)这样的构建变量来获取当前的构建信息,但是我可以得到$(Build.Previous.SourceVersion)之类的东西吗?

I can get current build information through the build variables like $(Build.SourceVersion) but can I get something like $(Build.Previous.SourceVersion)?

推荐答案

以前的构建信息没有内置变量,解决方法是您可以调用

There aren’t the built-in variables for previous build information, the workaround is that you can call Builds REST API (can be filter status, such as completed, inProgress) through PowerShell during this build. (The first item of the result is the newest one)

$base64authinfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $User, $Password)))
$responseFromGet = Invoke-RestMethod -Method Get -ContentType application/json -Uri $Uri -Headers @{Authorization=("Basic {0}" -f $base64authinfo)}

一些有关调用REST API的文章:使用PowerShell调用VSTS API VSTS/TFS REST API:基础知识以及构建和发行版

Some articles about calling REST API: Calling VSTS APIs with PowerShell, VSTS/TFS REST API: The basics and working with builds and releases

您可以使用变量System.AccessToken的值作为密码(在选项"选项卡中选中允许脚本访问OAuth令牌选项),并且用户名可以是任意值.

You can use value of System.AccessToken variable as password (Check Allow scripts to access OAuth token option in Options tab) and username can be anything.

这篇关于检查VSTS(VSTS API)中的先前版本信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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