Skip to content

Add Support for Jenkins Folder Jobs #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion Jenkins.Net/Internal/Commands/ArtifactGetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public ArtifactGetCommand(IJenkinsContext context, string jobName, string buildN
throw new ArgumentException("'filename' cannot be empty!");

var urlFilename = filename.Replace('\\', '/');
Url = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "artifact", urlFilename);
var postfix = $"artifact/{urlFilename}";

Url = ConstructUrl(context.BaseUrl, jobName, buildNumber, postfix);
UserName = context.UserName;
Password = context.Password;
Crumb = context.Crumb;
Expand Down
2 changes: 1 addition & 1 deletion Jenkins.Net/Internal/Commands/BuildGetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public BuildGetCommand(IJenkinsContext context, string jobName, string buildNumb
if (string.IsNullOrEmpty(buildNumber))
throw new ArgumentException("'buildNumber' cannot be empty!");

Url = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "api/xml");
Url = ConstructUrl(context.BaseUrl, jobName, buildNumber, "api/xml");
UserName = context.UserName;
Password = context.Password;
Crumb = context.Crumb;
Expand Down
21 changes: 21 additions & 0 deletions Jenkins.Net/Internal/JenkinsHttpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using System.Collections.Generic;


#if NET_ASYNC
using System.Threading;
Expand Down Expand Up @@ -154,5 +156,24 @@ private static string RemoveXmlDeclaration(string xml)
const string pattern = @"<\?xml[^\>]*\?>";
return Regex.Replace(xml, pattern, string.Empty);
}

internal string ConstructUrl(string baseUrl, string jobName, string buildNumber,string postfix)
{
var jobParts = jobName.Split(['/'], StringSplitOptions.RemoveEmptyEntries);
var urlParts = new List<string> { baseUrl };

foreach (var part in jobParts)
{
urlParts.Add("job");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look correct, should you be inserting "job" for every part?

urlParts.Add(part);
}

urlParts.Add(buildNumber);
urlParts.Add(postfix);

return NetPath.Combine(urlParts.ToArray());
}


}
}