Jenkins.NET
Jenkins.NET copied to clipboard
Handle complex job names
Jenkins api follows the pattern {baseUrl}/job/{JOB_NAME}
. However, if we have jobs nested in folders the job the pattern is {baseUrl}/job/{path}/job/{to}/job/{folder}job/{finalName}
. In the UI, Jenkins shows this job name as path/to/folder/finalName
.
On my first attempt at consuming the library I passed in the job name as shown in the UI. Perhaps you can consider expanding it so that either works or make it clearer which format is expected.
I can't seem to get child jobs from Jobs, so this library doesn't really work for me. Or is there something i misunderstand?
The Jenkins REST API does return the child jobs. If this library isn't exposing that we should be able to modify it simply enough.
I ended up doing my own custom API manipulation for my own needs and got ALL jobs like this.
private async Task<IEnumerable<string>> GetJobs(HttpClient client, Uri url)
{
var list = new List<string>();
var xml = XDocument.Parse(await client.GetStringAsync(new Uri(url, "api/xml")));
var jobs = xml.XPathSelectElements("//job/url").Select(x => x.Value).ToList();
if (jobs.Any())
{
list.AddRange(jobs);
var jobTasks = jobs.Select(async job => await GetJobs(client, new Uri(job)));
var results = await Task.WhenAll(jobTasks.ToArray());
jobs.AddRange(results.SelectMany(x => x));
}
return jobs;
}
@pjmagee I had to look at this twice to see what you were actually doing, I didn't catch the inner job lookup on first pass. The first portion of what your doing already exists in the Jenkins
class under the Jobs
property. You can use this to retrieve all Job urls as you are above.
var client = new JenkinsClient(...);
return client.Get().Jobs.Select(x => x.Url);
Unfortunately there is currently no way to lookup the details for that job, since the JobGetCommand
relies on the flat url structure.
@petelopez Sorry, to be honest I don't even use Jenkins anymore so this project has become secondary. With the growing number of user for this library though, I'm trying to come back and maintain requests. I think this is a good request and should be implemented, but it may take me a bit of time to setup Jenkins again and create a nested job layout for testing.
Based on your example though, it looks like a user should be able to pass "path/to/folder/finalName" as the jobName argument, and the library can just split on /
and prefix every segment with job/
.
So... what do I pass in as the "job name" when I have a child job? Passing in the URL doesn't work
Edit: nevermind, figured it out: the syntax is SomeJob/job/SomeChildJob