jenkins_api 0.3.0

Bindings for the Jenkins JSON API
Documentation

jenkins-api.rs License: MIT Build Status Realease Doc Crate

Bindings to Jenkins JSON API

The API docs for the master branch are published here.

Example

extern crate failure;

extern crate jenkins_api;

use jenkins_api::{JenkinsBuilder, BuildStatus};

fn main() -> Result<(), failure::Error> {
    let jenkins = JenkinsBuilder::new("http://localhost:8080")
        .with_user("user", Some("password"))
        .build()?;

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

    let to_build = if let Some(short_build) = job.last_build()?.clone() {
        let build = short_build.get_full_build(&jenkins)?;
        println!(
            "last build for job {} at {} was {:?}",
            job.name()?, build.timestamp()?, build.result()?
        );
        build.result()? != BuildStatus::Success
    } else {
        println!("job {} was never built", job.name()?);
        true
    };

    if to_build {
        println!("triggering a new build");
        job.build(&jenkins)?;
    }
    Ok(())
}