Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Jenkins.Net/IJenkinsContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using JenkinsNET.Models;

namespace JenkinsNET
Expand Down Expand Up @@ -30,6 +31,11 @@ public interface IJenkinsContext
/// </summary>
string ApiToken {get; set;}

/// <summary>
/// [optional] Extra HTTP headers to include on every request
/// </summary>
Dictionary<string, string> ExtraHeaders {get; set;}

/// <summary>
/// [optional] Jenkins CSRF Crumb.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Jenkins.Net/Internal/Commands/ArtifactGetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public ArtifactGetCommand(IJenkinsContext context, string jobName, string buildN
Url = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "artifact", urlFilename);
UserName = context.UserName;
Password = context.Password;
ExtraHeaders = context.ExtraHeaders;
Crumb = context.Crumb;

OnWrite = request => {
Expand Down
1 change: 1 addition & 0 deletions Jenkins.Net/Internal/Commands/BuildGetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public BuildGetCommand(IJenkinsContext context, string jobName, string buildNumb
Url = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "api/xml");
UserName = context.UserName;
Password = context.Password;
ExtraHeaders = context.ExtraHeaders;
Crumb = context.Crumb;

OnWrite = request => {
Expand Down
1 change: 1 addition & 0 deletions Jenkins.Net/Internal/Commands/BuildOutputCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public BuildOutputCommand(IJenkinsContext context, string jobName, string buildN
Url = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "consoleText");
UserName = context.UserName;
Password = context.Password;
ExtraHeaders = context.ExtraHeaders;
Crumb = context.Crumb;

OnRead = response => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public BuildProgressiveHtmlCommand(IJenkinsContext context, string jobName, stri
Url = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "logText/progressiveHtml");
UserName = context.UserName;
Password = context.Password;
ExtraHeaders = context.ExtraHeaders;
Crumb = context.Crumb;

OnWrite = request => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public BuildProgressiveTextCommand(IJenkinsContext context, string jobName, stri
Url = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "logText/progressiveText");
UserName = context.UserName;
Password = context.Password;
ExtraHeaders = context.ExtraHeaders;
Crumb = context.Crumb;

OnWrite = request => {
Expand Down
1 change: 1 addition & 0 deletions Jenkins.Net/Internal/Commands/CrumbGetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public CrumbGetCommand(IJenkinsContext context)
Url = NetPath.Combine(context.BaseUrl, "crumbIssuer/api/xml");
UserName = context.UserName;
Password = context.Password;
ExtraHeaders = context.ExtraHeaders;

OnWrite = request => {
request.Method = "GET";
Expand Down
1 change: 1 addition & 0 deletions Jenkins.Net/Internal/Commands/JenkinsGetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public JenkinsGetCommand(IJenkinsContext context)

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

OnWrite = request => {
Expand Down
1 change: 1 addition & 0 deletions Jenkins.Net/Internal/Commands/JobBuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public JobBuildCommand(IJenkinsContext context, string jobName)
Url = NetPath.Combine(context.BaseUrl, "job", jobName, "build?delay=0sec");
UserName = context.UserName;
Password = context.Password;
ExtraHeaders = context.ExtraHeaders;
Crumb = context.Crumb;

OnWrite = request => {
Expand Down
1 change: 1 addition & 0 deletions Jenkins.Net/Internal/Commands/JobCreateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public JobCreateCommand(IJenkinsContext context, string jobName, JenkinsProject

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

OnWrite = request => {
Expand Down
1 change: 1 addition & 0 deletions Jenkins.Net/Internal/Commands/JobDeleteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public JobDeleteCommand(IJenkinsContext context, string jobName)
Url = NetPath.Combine(context.BaseUrl, "job", jobName, "doDelete");
UserName = context.UserName;
Password = context.Password;
ExtraHeaders = context.ExtraHeaders;
Crumb = context.Crumb;

OnWrite = request => {
Expand Down
1 change: 1 addition & 0 deletions Jenkins.Net/Internal/Commands/JobGetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public JobGetCommand(IJenkinsContext context, string jobName)

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

OnWrite = request => {
Expand Down
1 change: 1 addition & 0 deletions Jenkins.Net/Internal/Commands/JobGetConfigCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public JobGetConfigCommand(IJenkinsContext context, string jobName)

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

OnWrite = request => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public JobUpdateConfigurationCommand(IJenkinsContext context, string jobName, Je

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

OnWrite = request => {
Expand Down
1 change: 1 addition & 0 deletions Jenkins.Net/Internal/Commands/QueueGetItemCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public QueueGetItemCommand(IJenkinsContext context, int itemNumber)
Url = NetPath.Combine(context.BaseUrl, "queue/item", itemNumber.ToString(), "api/xml");
UserName = context.UserName;
Password = context.Password;
ExtraHeaders = context.ExtraHeaders;
Crumb = context.Crumb;

OnWrite = request => {
Expand Down
1 change: 1 addition & 0 deletions Jenkins.Net/Internal/Commands/QueueItemListCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public QueueItemListCommand(IJenkinsContext context)
Url = NetPath.Combine(context.BaseUrl, "queue/api/xml");
UserName = context.UserName;
Password = context.Password;
ExtraHeaders = context.ExtraHeaders;
Crumb = context.Crumb;

OnWrite = request => {
Expand Down
6 changes: 6 additions & 0 deletions Jenkins.Net/Internal/JenkinsHttpCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using JenkinsNET.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
Expand All @@ -19,6 +20,7 @@ internal class JenkinsHttpCommand
public string Url {get; set;}
public string UserName {get; set;}
public string Password {get; set;}
public Dictionary<string, string> ExtraHeaders {get; set;}
public JenkinsCrumb Crumb {get; set;}
public Action<HttpWebRequest> OnWrite {get; set;}
public Action<HttpWebResponse> OnRead {get; set;}
Expand Down Expand Up @@ -67,6 +69,10 @@ private HttpWebRequest CreateRequest()
request.AllowAutoRedirect = true;
request.KeepAlive = true;

if (ExtraHeaders != null)
foreach (var header in ExtraHeaders)
request.Headers.Add(header.Key, header.Value);

if (Crumb != null)
request.Headers.Add(Crumb.CrumbRequestField, Crumb.Crumb);

Expand Down
7 changes: 7 additions & 0 deletions Jenkins.Net/JenkinsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using JenkinsNET.Internal.Commands;
using JenkinsNET.Models;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -28,6 +29,11 @@ public class JenkinsClient : IJenkinsContext, IJenkinsClient
/// </summary>
public string ApiToken {get; set;}

/// <summary>
/// [optional] Extra HTTP headers to include on every request
/// </summary>
public Dictionary<string, string> ExtraHeaders {get; set;}

/// <summary>
/// Gets or sets the security Crumb to use on API requests.
/// </summary>
Expand Down Expand Up @@ -90,6 +96,7 @@ public JenkinsClient(IJenkinsContext context) : this(context.BaseUrl)
this.UserName = context.UserName;
this.ApiToken = context.ApiToken;
this.Password = context.Password;
this.ExtraHeaders = context.ExtraHeaders;
this.Crumb = context.Crumb;
}

Expand Down