Beispiel #1
0
        /// <summary>
        ///     Get the XML for a job
        /// </summary>
        /// <param name="jenkinsClient">IJobDomain to bind the extension method to</param>
        /// <param name="jobName">the name of the job</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>XDocument</returns>
        public static async Task <XDocument> GetXmlAsync(this IJobDomain jenkinsClient, string jobName, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (jobName == null)
            {
                throw new ArgumentNullException(nameof(jobName));
            }
            Log.Debug().WriteLine("Retrieving job XML for {0}", jobName);
            var jobXmlUri = jenkinsClient.JenkinsBaseUri.AppendSegments("job", jobName, "config.xml");

            jenkinsClient.Behaviour.MakeCurrent();

            var response = await jobXmlUri.GetAsAsync <HttpResponse <XDocument> >(cancellationToken).ConfigureAwait(false);

            return(response.HandleErrors());
        }
Beispiel #2
0
        /// <summary>
        /// Delete job by name
        /// </summary>
        /// <param name="jenkinsClient">IJobDomain to bind the extension method to</param>
        /// <param name="jobName">name of the job to delete</param>
        /// <param name="cancellationToken">CancellationToken</param>
        public static async Task DeleteAsync(this IJobDomain jenkinsClient, string jobName, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (jobName == null)
            {
                throw new ArgumentNullException(nameof(jobName));
            }
            Log.Debug().WriteLine("Deleting job {0}", jobName);

            var deleteJobUri = jenkinsClient.JenkinsBaseUri.AppendSegments("job", jobName, "doDelete");

            jenkinsClient.Behaviour.MakeCurrent();

            var response = await deleteJobUri.PostAsync <HttpResponse>(null, cancellationToken).ConfigureAwait(false);

            response.HandleStatusCode();
        }
Beispiel #3
0
        /// <summary>
        /// Create job
        /// </summary>
        /// <param name="jenkinsClient">IJobDomain to bind the extension method to</param>
        /// <param name="jobName">name of the job to create</param>
        /// <param name="jobXmlDocument">XDocument with config.xml for the job</param>
        /// <param name="cancellationToken">CancellationToken</param>
        public static async Task CreateAsync(this IJobDomain jenkinsClient, string jobName, XDocument jobXmlDocument, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (jobName == null)
            {
                throw new ArgumentNullException(nameof(jobName));
            }
            Log.Debug().WriteLine("Creating job {0}", jobName);

            var createJobUri = jenkinsClient.JenkinsBaseUri.AppendSegments("createItem").ExtendQuery("name", jobName);

            jenkinsClient.Behaviour.MakeCurrent();

            var response = await createJobUri.PostAsync <HttpResponse>(jobXmlDocument, cancellationToken).ConfigureAwait(false);

            response.HandleStatusCode();
        }