mockersf / jenkins-api.rs

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

Is there a way to download an artifact? #80

Open elazarl opened 2 years ago

elazarl commented 2 years ago

It is currently possible with the API to get a list of the artifacts of the job. It is even possible to get the URL of the specific artifact:

fn main() -> Result<(), Box<dyn Error>> {
    let user = "elazarl";
    let token = "d4bf510c5963520355749a7da277182aaa";
    let jenkins = JenkinsBuilder::new("http://localhost:8000/")
        .with_user(user, Some(token))
        .build().unwrap();
    let build = jenkins.get_build("End2EndReport", 2590)?;
    println!("curl --user {}:{} {}artifact/{}", user, token, build.url, build.artifacts[0].relative_path);
    Ok(())
}

However I couldn't find a way to use Jenkins to download it:

  1. The client itself seems to be private, and there's no way to access it.
  2. All methods of getting a generic object or Path from jenkins, seems to convert it to json, hence disabling download of logs.

Is there a way to download a generic artifact?

Something like

impl Jenkins {
    pub fn get_artifact(build: Build, artifact: Artifact) -> Box<dyn std::io::Read> {
        let query = self
            .client
            .get(&format!("{}artifact/{}", &build.url, artifact.relative_path));
        Ok(Self::error_for_status(self.send(query)?)?)
    }

Does that make sense? Is there any other way to achieve that?