1
votes

I'm trying to use C# to trigger a remote Jenkins job which has parameters. The job triggers, but I have two problems. First, the parameter is not being received by Jenkins, and two, I'm receiving no response from Jenkins. Here is my code snippet:

`string url = "http://172.30.25.33:8080/job/CloudTeam/job/Tests/job/TestJob/buildWithParameters";

        using (var wb = new WebClient())
        {
            string json = @"{""parameter"": [{""testvar"" : ""user""" + @"""}]`";


                           //return json;

            string password = "mypassword";
            string username = "myuser";

            string basicAuthToken = Convert.ToBase64String(Encoding.Default.GetBytes(username + ":" + password));
            wb.Headers["Authorization"] = "Basic " + basicAuthToken;

            wb.Headers[HttpRequestHeader.ContentType] = "application/json";

            return wb.UploadString(url, json);
        }`
1

1 Answers

0
votes

Microsoft does not recommend using WebClient API for new development. Instead, they recommend using HttpClient.

I would recommend using NewtonSoft's Json.NET (or similar library) to build the JSON data instead of crafting it by hand.

Have you tried using a tool like Postman to validate the request?