从Powershell启动vNext构建并获取工件 [英] Start vNext build from Powershell and get artifacts

查看:92
本文介绍了从Powershell启动vNext构建并获取工件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了自动化我们的部署,我想基于给定的ChangeSetId重建一个应用程序.构建完成后,我想获取构建(.exe)的 artifacts ,以便我们进行部署.为了解决这个问题,我将重点放在从构建中获取工件"部分.

In order to automate our deployments, I would like to rebuild an application, based on a given ChangeSetId. Once this build has completed, I want to get the artifacts of the build (the .exe), so we can deploy them. For the sake of the question I am focussing on the 'Get artifacts from build' part.

出于DevOps的目的,我想使用PowerShell,因为它应该能够访问TFS API库,并且因为MS建议使用它.

For DevOps purposes, I'd like to use PowerShell, since it should be able to access the TFS API libraries and because MS recommends using it.

环境

我已经在On Premise TFS 2015服务器(运行良好)中设置了Builds,并在此构建后添加了 VSO任务发布工件".到目前为止,一切都很好. 已发布的工件将存储在服务器上,这基本上意味着我必须下载连接到构建的工件-每个现有的构建都将链接其工件-比在我的书中放个UNC更好.

I've set up Builds in our On Premise TFS 2015 server (which are working neatly) - and added a VSO task 'Publish artifacts' after this build. So far so good. The published artifacts is are to be stored on the Server, which basically means I have to download the artifacts connected to build - every existing build will have its artifacts linked - which is better then an UNC drop in my book.

没有挑战,我没有挑战.我如何以编程方式访问这些工件,第3步?

No comes my challenge; how do I programmaticaly access these artifacts, step 3?

  1. 获取ChangeSetId的来源
  2. 具有给定配置的MSBuild应用程序
  3. 使用PowerShell获取构建工件
  4. 使用发布管理(以及Powershell)部署到环境
  1. Get Sources for ChangeSetId
  2. MSBuild application with given configuration
  3. Get build Artifacts using PowerShell
  4. Deploy to environment using Release Management (Powershell as well)

推荐答案

TFS 2015随附新的REST API ,其中包括用于获取特定内部版本工件的方法.我将通过以下方式应对您的挑战:

TFS 2015 comes with the new REST API, and it includes the method to get the artifacts of the specific build. I would approach your challenge in the following way:

  • 在发布工件"步骤之后添加"PowerShell脚本"构建步骤
  • 在该PowerShell脚本中:
    • 获取当前版本的ID. TFS公开了许多预定义变量,并且构建ID为那里.所有这些变量最终都作为环境变量,并且获取构建工件发出Web请求.从API描述中可以看到,您只需提供构建ID
    • 然后,解析JSON响应-downloadUrl属性包含用于下载压缩为单个归档文件的构建的所有工件的链接
    • 最后,提取档案并提取您需要的那些工件.也许,您也希望在此步骤中将其部署到测试环境中
    • Add a "PowerShell script" build step after your "Publish artifacts" step
    • In that PowerShell script:
      • Get the ID of the current build. TFS exposes a number of predefined variables, and build ID is there. All those variables end up as environment variable, and this post can help you read the appropriate one from your PowerShell script
      • Next, make a web request to get build artifacts. As you can see from the API description, you'll have to provide just the build ID
      • Then, parse the JSON response - the downloadUrl property contains the link to download all the artifacts of the build zipped as a single archive
      • Finally, extract the archive and pick up those artifacts you need. Perhaps, you'd like to deploy it to your testing environment in this step as well

      希望这会有所帮助.

      这篇关于从Powershell启动vNext构建并获取工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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