mockersf / jenkins-api.rs

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

can you trigger a build with this api? #35

Closed jlgerber closed 4 years ago

jlgerber commented 5 years ago

I don't see a way of providing a build job's url. ie here is my build url "/view/DDPipeline/job/Plans/job/BuildTagPipeline/build" here is my server url "myserver.something.com:5000 and assume some parameters.

I have tried including it as part of the server url but that does not work...

mockersf commented 5 years ago

yes, please see the example in the readme : https://github.com/mockersf/jenkins-api.rs#example

jlgerber commented 5 years ago

Sorry. i must be pretty dense. Looking at the example, I dont see anywhere to supply an additional url. What is the method that would allow me to do this?

mockersf commented 5 years ago

Sorry for the delay.

With this API, you can't supply a build URL directly, as with Jenkins add ons, there is now way to be sure that an URL is a buildable job.

You have to get the job by name from Jenkins:

    let job = jenkins.get_job("job name").unwrap();

and then try to "cast" this job into a variant that can be built:

   job.as_variant::<jenkins_api::job::FreeStyleProject>().unwrap()

There are existing bindings for the following job types : https://docs.rs/jenkins_api/0.5.2/jenkins_api/job/index.html All the job types that can be built implements the trait BuildableJob

If your job is not one of those, you can either implement the Job specialisation yourself for it in you crate by implementing the traits Job, Class and BuildableJob or you can tell me what kind of jobs it is and I'll try to add it to the list