mockersf / jenkins-api.rs

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

Updating other content in view besides jobs? #42

Closed webbrandon closed 4 years ago

webbrandon commented 5 years ago

Goal: I want to post the pipeline stages in the status view in Jenkins similar to the stages view plugin.

I see methods that allow you to add a job to an existing view but not one for the additional content such as stage block data. Is there a function that would allow me to update this view with the desired result?

1dila

Or simpler text implementation:

Job #87   ->  (build succeeded) -> (test pass) -> (container pushed) -> Success 
Job #88   ->  (build succeeded) -> (test pass) -> (container pushed) -> Success 
Job #89   ->  (build succeeded) -> (test pass) -> (unable to push) -> Fail 

Admittedly it has been hard finding details or documents on implementing something like this so far. I feel the solution I need may be hidden in the Jenkins JIRA system in a tickets comments or the DSL codebase for pipelines or jobs.

I have a question for something simliar to this request on stack overflow

mockersf commented 4 years ago

sadly Jenkins API for pipelines is pretty hard. You can view the json from one of your pipeline build, the REST API link (on the bottom right) and json api the interesting part is in action, by default it should look something like

{
  "_class" : "org.jenkinsci.plugins.workflow.job.WorkflowRun",
  "actions" : [
    {
      "_class" : "hudson.model.CauseAction",
      "causes" : [
        {
          "_class" : "hudson.model.Cause$UserIdCause",
          "shortDescription" : "Started by user user",
          "userId" : "user",
          "userName" : "user"
        }
      ]
    },
    {

    },
    {

    },
    {
      "_class" : "org.jenkinsci.plugins.workflow.support.steps.input.ApproverAction"
    },
    {

    },
    {

    },
    {

    },
    {
      "_class" : "org.jenkinsci.plugins.workflow.job.views.FlowGraphAction"
    },
    {

    },
    {

    }
  ],
...
}

you can add a parameter &depth=1 and it will start displaying more info, and &depth=2 will start looking interesting

using this api, you can have something similar with

    let jenkins = JenkinsBuilder::new(JENKINS_URL)
        .with_depth(2)
        .build()
        .unwrap();

    let build = jenkins.get_build("pipeline job", 1);
    println!(
        "{:#?}",
        build
            .unwrap()
            .actions
            .iter()
            .filter_map(|action| action
                .as_variant::<jenkins_api::action::FlowGraphAction>()
                .ok())
            .next()
    );
mockersf commented 4 years ago

for a simple pipeline with 4 steps

Screenshot 2019-11-05 at 04 40 38

it gives a lot of data : https://gist.github.com/mockersf/e5c011d8140be2100e57bd8918d0d22e