locked
XAML REST API Sample RRS feed

  • Question

  • Hello,

    i want to write  a simple tool, which helps me starting builds quickly.
    For that i will create a xaml build definition with some parameters.
    And now i want to start that xaml build via REST API.

    My Questions:

    - how can i define variables in a xaml build ?

    - how can i start a build with this buid definition using the variables over the rest api? Any Examplesm or Code snippets?

    Thursday, July 7, 2016 6:51 PM

Answers

  • Hi Flash05,

    Thank you for posting here.

    - how can i define variables in a xaml build ?

    What variables you want to defined, do you mean define a variable for activities in build process template?

    - how can i start a build with this buid definition using the variables over the rest api?

    You could take a look at the code below to queue a build using TFS rest API.

    Reference link: https://www.visualstudio.com/en-us/docs/integrate/api/build/builds#queue-a-build

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://servername:8080/tfs/CollectionName/ProjectName/_apis/build/builds?api-version=2.0");
                request.Credentials = CredentialCache.DefaultNetworkCredentials;
                request.Method = "Post";
                request.ContentType = "application/json";
                Stream stream = request.GetRequestStream();
                string json = "{\"definition\":{\"id\":2}}"; //The number '2' is build definition id. Change '2' to your build definition id.
                byte[] buffer = Encoding.UTF8.GetBytes(json);
                stream.Write(buffer, 0, buffer.Length);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    
                Console.Write(response.StatusCode);
                using (var streamReader = new StreamReader(response.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                }
    
                Console.ReadLine();


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, July 8, 2016 7:42 AM
    Moderator