使用Powershell对Visual Studio Online构建进行排队

时间:2015-07-21 18:12:27

标签: powershell tfsbuild tfs2013 azure-devops

有没有办法排队Visual Studio Online" Build Definition" - 与#34; XAML定义" - 使用Powershell。

我有以下脚本:

#// CONFIGURATION ITEMS ============================================
$serverName="https://example.visualstudio.com/DefaultCollection"
$username = "example@example.com"
$password = "mypassword";
$teamProject = "Web"
$buildDefinition = "Test"
#// ================================================================


[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.VersionControl.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
$assembly = ("Microsoft.TeamFoundation.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

$source =  @"
using System;
using System.Collections.Generic;
using System.Text;
using  Microsoft.TeamFoundation.Client;
using System.Net;
public class ConnectByImplementingCredentialsProvider : ICredentialsProvider
    {
        public ICredentials GetCredentials(Uri uri, ICredentials iCredentials)
        {
            return new NetworkCredential(" $username ", " $password ");
        }

        public void NotifyCredentialsAuthenticated(Uri uri)
        {
            throw new ApplicationException("Unable to authenticate");
        }
    }
"@

Add-Type -ReferencedAssemblies $assembly -TypeDefinition $source -Language CSharp 
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName, (New-Object ConnectByImplementingCredentialsProvider))
$tfs.EnsureAuthenticated() 
$buildserver = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$definition = $buildserver.GetBuildDefinition($teamProject, $buildDefinition)
$request = $definition.CreateBuildRequest()
$buildserver.QueueBuild($request, "None") 

...但GetBuildDefinition()仅返回XAML定义下列出的项目。 : - (

1 个答案:

答案 0 :(得分:0)

更新网址: https://www.visualstudio.com/en-us/docs/integrate/api/build/builds#queue-a-build

您是否尝试过使用VSO REST api对构建进行排队?请参阅此处的“请求构建”部分 - https://www.visualstudio.com/integrate/api/build/requests