mockersf / jenkins-api.rs

Rust client for Jenkins API
MIT License
26 stars 17 forks source link

How do you retrieve a job in a folder ? #51

Closed darlaam closed 4 years ago

darlaam commented 4 years ago

Let's we have a job in a folder (something like http://jenkins:8080/job/folder/job/myjob)

First attempt

let myjob = jenkins.get_job("folder/job/myjob").unwrap();

-> Result::unwrap() on anErrvalue: Error(Status(404), "http://jenkins:8080/job/folder%2Fjob%2Fmyjob/api/json?depth=1")

Ok.There is some URL encoding done there (namely in JobName and Name::Name()). Doesn't seems the way to go then...

No need to say that the simple get_job("myjob") is also a 404.

Attempt two Can I get the job from the folder ?

let folder = jenkins.get_job("folder").unwrap();

-> Result::unwrap() on an Err value: Error(Json(Error("missing fieldbuildable", line: 1, column: 14901))) Yes... right... Indeed, folders don't have a buildable field...

Attempt three From home ? Same problem than 2 : I can get the Home folder, list jobs (somes are actually folders) and panic trying to get a full job (which it's not... so quite logical).

Attempt four With get_object_as

let job = jenkins
            .get_object_as(
                jenkins_api::client::Path::Raw {
                    path: "/job/folder/job/myjob"
                },
                jenkins_api::client::TreeBuilder::new()
                    .with_field("name")
                    .with_field("url").build(),
            )
            .unwrap();

        let myjob = folder.get_full_job(&jenkins).unwrap();

Better : I cant get the job, but I can't get the full fledge job : Result::unwrap() on an Err value: ParseIntError { kind: InvalidDigit } Seems we are paddling in Path.url_to_path method : the url is detected as a build one...

To conclude So question is : is it possible to access a job in a folder ? It seems that the code exect the job to be at the root of jenkins.

seanpianka commented 4 years ago

Hi @mockersf, thanks for the great work on this package! I am looking forward to using it on one of my group's Jenkins installations.

Could you talk about any progress that has been made to add support for jobs nested within folders? Our existing Jenkins installation makes heavy use of jobs within folders (nested one or two levels deep).

Without this support, this library is unusable for our existing installation.

mockersf commented 4 years ago

you can now get a folder and its jobs:

    let folder: jenkins_api::job::Folder = jenkins
        .get_job("test_folder")
        .unwrap()
        .as_variant::<jenkins_api::job::Folder>()
        .unwrap();
    let job = folder.jobs[0].get_full_job(&jenkins);