TFS Release Artifacts - 如何链接版本控制工件?

时间:2017-07-05 15:04:00

标签: tfs azure-devops release-management

我正在尝试设置一些PowerShell脚本,以便在我的TFS Release Agent上可用。

据我所知,到目前为止,这样做的方法是链接工件并引用TFS RM中PowerShell任务中的工件链接。

我遇到的麻烦是TFS RM工件只允许我在版本控制中下载整个团队项目,而我只希望将特定子文件夹中的powershell脚本下载到代理。

我收到一条错误消息:

字段(源存储库)工件应具有有效值

enter image description here

那么,如何将TFS的SUB文件夹链接为可下载的工件????

我可以使用自定义任务来完成此任务吗?

我还没有在MarketPLace中找到一个可以在TFS版本控制绑定中下载原始文件,并且可以在Release代理服务器上自由执行工作区。

2 个答案:

答案 0 :(得分:0)

你不能。在构建过程中发布工件。您可以轻松控制已发布的确切文件夹/文件。

答案 1 :(得分:0)

简单的方法是,您可以使用Get a file REST API来获取文件。

  1. 单击“在代理上运行”
  2. 选中允许脚本访问OAuth令牌选项(确保构建服务帐户具有下载文件的权限)
  3. 将PowerShell任务添加到发布定义(类型:内联脚本)
  4. 参数:

    -url '$(System.TeamFoundationCollectionUri)/_apis/tfvc/items?path=$/Scrum2015/ClassLibraryA/hello.ps1&api-version=1.0' -token "$(System.AccessToken)"  -filePath "$(System.DefaultWorkingDirectory)\hello.ps1"
    

    脚本:

    Param([string]$url,
      [string]$token,
      [string]$filePath
    )
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$token)))
    Invoke-WebRequest -Method Get -Uri $url -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -OutFile $filePath
    

    如果要下载文件夹中的多个文件,可以custom build task使用Microsoft Team Foundation Server Extended Client package调用PowerShell创建工作区并获取文件。