-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathJobBuildCommand.cs
More file actions
46 lines (37 loc) · 1.53 KB
/
JobBuildCommand.cs
File metadata and controls
46 lines (37 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using JenkinsNET.Exceptions;
using System;
namespace JenkinsNET.Internal.Commands
{
internal class JobBuildCommand : JenkinsHttpCommand
{
public JenkinsBuildResult Result {get; internal set;}
public JobBuildCommand(JenkinsClient client, string jobName) : base(client)
{
if (string.IsNullOrEmpty(jobName))
throw new ArgumentException("'jobName' cannot be empty!");
Path = $"job/{jobName}/build?delay=0sec";
OnWrite = request => {
request.Method = "POST";
};
OnRead = response => {
if (response.StatusCode != System.Net.HttpStatusCode.Created)
throw new JenkinsJobBuildException($"Expected HTTP status code 201 but found {(int)response.StatusCode}!");
Result = new JenkinsBuildResult {
QueueItemUrl = response.GetResponseHeader("Location")
};
};
#if NET_ASYNC
OnWriteAsync = async (request, token) => {
request.Method = "POST";
};
OnReadAsync = async (response, token) => {
if (response.StatusCode != System.Net.HttpStatusCode.Created)
throw new JenkinsJobBuildException($"Expected HTTP status code 201 but found {(int)response.StatusCode}!");
Result = new JenkinsBuildResult {
QueueItemUrl = response.GetResponseHeader("Location")
};
};
#endif
}
}
}