public JobUpdateConfigurationCommand(IJenkinsContext context, string jobName, JenkinsProject job)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrEmpty(jobName))
            {
                throw new ArgumentException("Value cannot be empty!", nameof(jobName));
            }

            if (job == null)
            {
                throw new ArgumentNullException(nameof(job));
            }

            Url = NetPath.Combine(context.BaseUrl, "job", jobName, "config.xml");

            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            OnWriteAsync = async(request, token) => {
                request.Method      = "POST";
                request.ContentType = "application/xml";
                await WriteXmlAsync(request, job.Node, token);
            };
        }
예제 #2
0
        public JobDeleteCommand(IJenkinsContext context, string jobName)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrEmpty(jobName))
            {
                throw new ArgumentException("'jobName' cannot be empty!");
            }

            Url      = NetPath.Combine(context.BaseUrl, "job", jobName, "doDelete");
            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            OnWrite = request => {
                request.Method            = "POST";
                request.ContentLength     = 0;
                request.AllowAutoRedirect = false;
            };

        #if NET_ASYNC
            OnWriteAsync = async(request, token) => {
                request.Method            = "POST";
                request.ContentLength     = 0;
                request.AllowAutoRedirect = false;
            };
        #endif
        }
        public BuildProgressiveTextCommand(IJenkinsContext context, string jobName, string buildNumber, int start)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrEmpty(jobName))
            {
                throw new ArgumentException("'jobName' cannot be empty!");
            }

            if (string.IsNullOrEmpty(buildNumber))
            {
                throw new ArgumentException("'buildNumber' cannot be empty!");
            }

            Url      = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "logText/progressiveText");
            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            OnWriteAsync = async(request) => {
                request.Method      = "POST";
                request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";

                using (var requestStream = await request.GetRequestStreamAsync())
                    using (var writer = new StreamWriter(requestStream)) {
                        await writer.WriteAsync($"start={start}");
                    }
            };

            OnReadAsync = async response => {
                var hSize     = response.Headers["X-Text-Size"];
                var hMoreData = response.Headers["X-More-Data"];

                if (!int.TryParse(hSize, out var _size))
                {
                    throw new ApplicationException($"Unable to parse x-text-size header value '{hSize}'!");
                }

                var _moreData = string.Equals(hMoreData, bool.TrueString, StringComparison.OrdinalIgnoreCase);

                Result = new JenkinsProgressiveTextResponse {
                    Size     = _size,
                    MoreData = _moreData,
                };

                using (var stream = response.GetResponseStream()) {
                    if (stream == null)
                    {
                        return;
                    }

                    using (var reader = new StreamReader(stream)) {
                        Result.Text = await reader.ReadToEndAsync();
                    }
                }
            };
        }
예제 #4
0
        public QueueItemListCommand(IJenkinsContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Url      = NetPath.Combine(context.BaseUrl, "queue/api/xml");
            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            OnWrite = request => {
                request.Method = "GET";
            };

            OnRead = response => {
                using (var stream = response.GetResponseStream()) {
                    if (stream == null)
                    {
                        return;
                    }

                    var document = XDocument.Load(stream);
                    if (document.Root == null)
                    {
                        throw new ApplicationException("An empty response was returned!");
                    }

                    Result = document.XPathSelectElements("/queue/item")
                             .Select(node => new JenkinsQueueItem(node)).ToArray();
                }
            };
        }
예제 #5
0
        public CrumbGetCommand(IJenkinsContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Url      = NetPath.Combine(context.BaseUrl, "crumbIssuer/api/xml");
            UserName = context.UserName;
            Password = context.Password;

            OnWrite = request => {
                request.Method = "GET";
            };

            OnRead = response => {
                using (var stream = response.GetResponseStream()) {
                    if (stream == null)
                    {
                        return;
                    }

                    var document = XDocument.Load(stream);
                    if (document.Root == null)
                    {
                        throw new ApplicationException("An empty response was returned!");
                    }

                    Result = new JenkinsCrumb(document.Root);
                }
            };
        }
예제 #6
0
        public JobGetCommand(IJenkinsContext context, string jobName)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrEmpty(jobName))
            {
                throw new ArgumentException("Value cannot be empty!", nameof(jobName));
            }

            Url = NetPath.Combine(context.BaseUrl, "job", jobName, "api/xml");

            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            OnWrite = request => {
                request.Method = "GET";
            };

            OnReadAsync = async(response, token) => {
                var document = await ReadXmlAsync(response);

                Result = Activator.CreateInstance(typeof(T), document.Root) as T;
            };
        }
        public QueueGetItemCommand(IJenkinsContext context, int itemNumber)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Url      = NetPath.Combine(context.BaseUrl, "queue/item", itemNumber.ToString(), "api/xml");
            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            OnWrite = request => {
                request.Method = "POST";
            };

            OnRead = response => {
                using (var stream = response.GetResponseStream()) {
                    if (stream == null)
                    {
                        return;
                    }

                    var document = XDocument.Load(stream);
                    if (document.Root == null)
                    {
                        throw new ApplicationException("An empty response was returned!");
                    }

                    Result = new JenkinsQueueItem(document.Root);
                }
            };
        }
예제 #8
0
        public BuildGetCommand(IJenkinsContext context, string jobName, string buildNumber)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrEmpty(jobName))
            {
                throw new ArgumentException("'jobName' cannot be empty!");
            }

            if (string.IsNullOrEmpty(buildNumber))
            {
                throw new ArgumentException("'buildNumber' cannot be empty!");
            }

            Url      = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "api/xml");
            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            OnWrite = request => {
                request.Method = "POST";
            };

            OnReadAsync = async(response, token) => {
                var document = await ReadXmlAsync(response);

                var args = new object[] { document.Root };
                Result = Activator.CreateInstance(typeof(T), args) as T;
            };
        }
예제 #9
0
        public JenkinsGetCommand(IJenkinsContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Url = NetPath.Combine(context.BaseUrl, "api/xml");

            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            OnWrite = request => {
                request.Method = "GET";
            };

            OnRead = response => {
                var document = ReadXml(response);
                Result = new Jenkins(document.Root);
            };

        #if NET_ASYNC
            OnWriteAsync = async(request, token) => {
                request.Method = "GET";
            };

            OnReadAsync = async(response, token) => {
                var document = await ReadXmlAsync(response);

                Result = new Jenkins(document.Root);
            };
        #endif
        }
예제 #10
0
        public JobBuildCommand(IJenkinsContext context, string jobName)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrEmpty(jobName))
            {
                throw new ArgumentException("'jobName' cannot be empty!");
            }

            Url      = NetPath.Combine(context.BaseUrl, "job", jobName, "build?delay=0sec");
            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            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")
                };
            };
        }
예제 #11
0
        public BuildOutputCommand(IJenkinsContext context, string jobName, string buildNumber)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrEmpty(jobName))
            {
                throw new ArgumentException("'jobName' cannot be empty!");
            }

            if (string.IsNullOrEmpty(buildNumber))
            {
                throw new ArgumentException("'buildNumber' cannot be empty!");
            }

            Url      = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "consoleText");
            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            OnReadAsync = async(response, token) => {
                using (var stream = response.GetResponseStream()) {
                    if (stream == null)
                    {
                        return;
                    }

                    var encoding = TryGetEncoding(response.ContentEncoding, Encoding.UTF8);
                    Result = await stream.ReadToEndAsync(encoding, token);
                }
            };
        }
예제 #12
0
        public JobGetConfigCommand(IJenkinsContext context, string jobName)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrEmpty(jobName))
            {
                throw new ArgumentException("Value cannot be empty!", nameof(jobName));
            }

            Url = NetPath.Combine(context.BaseUrl, "job", jobName, "config.xml");

            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            OnWrite = request => {
                request.Method = "GET";
            };

            OnReadAsync = async response => {
                var document = await ReadXmlAsync(response);

                Result = new JenkinsProject(document.Root);
            };
        }
예제 #13
0
        public ArtifactGetCommand(IJenkinsContext context, string jobName, string buildNumber, string filename)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrEmpty(jobName))
            {
                throw new ArgumentException("'jobName' cannot be empty!");
            }

            if (string.IsNullOrEmpty(buildNumber))
            {
                throw new ArgumentException("'buildNumber' cannot be empty!");
            }

            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentException("'filename' cannot be empty!");
            }

            var urlFilename = filename.Replace('\\', '/');

            Url      = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "artifact", urlFilename);
            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            OnWrite = request => {
                request.Method = "POST";
            };

            OnRead = response => {
                using (var stream = response.GetResponseStream()) {
                    if (stream == null)
                    {
                        return;
                    }

                    try {
                        Result = new MemoryStream();
                        stream.CopyTo(Result);
                        Result.Seek(0, SeekOrigin.Begin);
                    }
                    catch {
                        Result?.Dispose();
                        throw;
                    }
                }
            };
        }
예제 #14
0
        public JobBuildWithParametersCommand(IJenkinsContext context, string jobName, IDictionary <string, string> jobParameters)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrEmpty(jobName))
            {
                throw new ArgumentException("'jobName' cannot be empty!");
            }

            if (jobParameters == null)
            {
                throw new ArgumentNullException(nameof(jobParameters));
            }

            var _params = new Dictionary <string, string>(jobParameters)
            {
                ["delay"] = "0sec",
            };

            var query = new StringWriter();

            WriteJobParameters(query, _params);

            Url      = NetPath.Combine(context.BaseUrl, "job", jobName, $"buildWithParameters?{query}");
            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            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"),
                };
            };
        }
예제 #15
0
        public JobCreateCommand(IJenkinsContext context, string jobName, JenkinsProject job)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (string.IsNullOrEmpty(jobName))
            {
                throw new ArgumentException("Value cannot be empty!", nameof(jobName));
            }

            if (job == null)
            {
                throw new ArgumentNullException(nameof(job));
            }

            Url = NetPath.Combine(context.BaseUrl, "createItem")
                  + NetPath.Query(new { name = jobName });

            UserName = context.UserName;
            Password = context.Password;
            Crumb    = context.Crumb;

            OnWrite = request => {
                request.Method      = "POST";
                request.ContentType = "application/xml";
                WriteXml(request, job.Node);
            };

        #if NET_ASYNC
            OnWriteAsync = async(request, token) => {
                request.Method      = "POST";
                request.ContentType = "application/xml";
                await WriteXmlAsync(request, job.Node, token);
            };
        #endif
        }
예제 #16
0
 internal JenkinsClientArtifacts(IJenkinsContext context)
 {
     this.context = context;
 }
예제 #17
0
 internal JenkinsClientBuilds(IJenkinsContext context)
 {
     this.context = context;
 }
예제 #18
0
 internal JenkinsClientQueue(IJenkinsContext context)
 {
     this.context = context;
 }
예제 #19
0
 internal JenkinsClientJobs(IJenkinsContext context)
 {
     this.context = context;
 }