Skip to content
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

Handle complex job names #19

Open
petelopez opened this issue Mar 2, 2019 · 5 comments
Open

Handle complex job names #19

petelopez opened this issue Mar 2, 2019 · 5 comments

Comments

@petelopez
Copy link
Contributor

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.

@pjmagee
Copy link

pjmagee commented Mar 27, 2019

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?

@petelopez
Copy link
Contributor Author

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.

@pjmagee
Copy link

pjmagee commented Mar 28, 2019

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;
}

@null511
Copy link
Owner

null511 commented May 28, 2019

@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/.

@christoffersch
Copy link

christoffersch commented Mar 22, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants