1

I'm learning Jenkins, I want to save Jenkins pipeline result, and then visit the result by Jenkins REST API.

Can this be achieved?

For example:

pipeline {
    agent  any
    stages {
        stage("calculate 1+1") {
               script{
                  def result = 0
                  result = 1+1
               }
         }
}
            

How should I save result and then visit it? (I can use Jenkins python package: Jenkins.get_build_info)

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Bryan Chen
  • 139
  • 1
  • 13
  • According Document in Jenkins, Can I custormize `currentBuild.result`? Is `currentBuild.result` is only a enum of `SUCCESS` `UNSTABLE` `FAILURE`? – Bryan Chen Oct 14 '21 at 11:01
  • Seems I can not save the result in `currentBuild.result` – Bryan Chen Oct 14 '21 at 11:19
  • `currentBuild.result` is enum. I suggest to use `writeFile` to write result to workspace, then use `archiveArtifacts` to store it as artifact. You can use REST API to get artifacts. – zett42 Oct 14 '21 at 11:52
  • 1
    Thank you @zett42 Here is a similar question: [link]https://stackoverflow.com/questions/59551174/jenkins-pipeline-to-return-results-file-after-build – Bryan Chen Oct 15 '21 at 01:50

1 Answers1

0

The result of a pipeline usually is a build somewhere in $WORKSPACE. You can make Jenkins archive such file(s) using archiveArtifacts and later retrieve them like Downloading artifacts from Jenkins using wget or curl

If instead you intend to store more metadata about the build (which would reside in build.xml) this is another story. Usually you need plugins that perform such work for you - I am not aware of generic pipeline steps that would do that.

Queeg
  • 7,748
  • 1
  • 16
  • 42