jansepar / node-jenkins-api

Jenkins API for NodeJS
MIT License
360 stars 173 forks source link

node-jenkins doesn't play well with folders plugin #17

Open ghost opened 10 years ago

ghost commented 10 years ago

In my jenkins installation at work because have many products we have regrouped jobs with folders plugin to make sure we do not end up with a huge mess. When calling the jenkins api for the list of all jobs on the server all we get is the list of folders not the job that are contained in them. is there a way around that?

signus commented 8 years ago

It's not easy, but it can certainly be done. Unfortunately the Jenkins API doesn't play nicely with folders either as it causes the URL to become sets of nested name/job/name/job/name/job items.

In my testing situation I was able to do this using async and I filter on a particular name. You can use this for particular qualifiers or use non-matching criteria. For example - all of my jobs have numbers in them, whereas the folders do not. However in job_info folders are still classified as a job. Here I just do a quick test with the nested names.

jenkins.job_info('Folder1', function(err, job) {
    if (err) throw err;

    async.forEach(job.jobs, function(item, callback) {
        if (item.name.match(/Folder2/g)) {
            jenkins.job_info('Folder1/job/' + item.name, function (ierr, intjob) {
                if (ierr) throw ierr;

                console.log(intjob);
            });
        }
    }, function (aerr) {
        throw aerr;
    });
});

Using this I see the jobs within a folder, and you can drill down further from there. Also make note that you can use the primaryView field to know the path of set of jobs you're querying.

It would certainly be nice to see better support for nested jobs/folders, for sure. However as messy as this is - I hope this helps you!