Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-33969

claim-plugin cannot be used with pipelines (workflows)

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      It seems that the claim plugin cannot be used anymore with the pipeline jobs in Jenkins (pipeline plugin, github-organization-plugin) – those using the Jenkinsfile.

      As these are quickly becoming the standard way of defining Jenkins jobs, we do need a way to enable claiming for them.

        Attachments

          Activity

          Hide
          mj_blue Mark Jones added a comment -

          To clarify I can successfully add the step in my JenkinsFile:

          {{step([$class: 'ClaimPublisher']) }}

          and I get the message on the build page 'This build was not claimed' but there is no link to claim the build. I am logged in as admin and can claim non pipeline builds.

          plugin version: V0.8
          Jenkins version: V2.12

          Show
          mj_blue Mark Jones added a comment - To clarify I can successfully add the step in my JenkinsFile: {{step( [$class: 'ClaimPublisher'] ) }} and I get the message on the build page 'This build was not claimed' but there is no link to claim the build. I am logged in as admin and can claim non pipeline builds. plugin version: V0.8 Jenkins version: V2.12
          Hide
          ramyaa Ramya Authappan added a comment -

          Hi is there a way to workaround this issue?

          I add this in my Jenkinsfile:
          step([$class: 'ClaimPublisher'])

          But i see nothing after the build faliure.

          Jenkins version: 2.20
          Claim Plugin Version: 2.8

          Show
          ramyaa Ramya Authappan added a comment - Hi is there a way to workaround this issue? I add this in my Jenkinsfile: step( [$class: 'ClaimPublisher'] ) But i see nothing after the build faliure. Jenkins version: 2.20 Claim Plugin Version: 2.8
          Hide
          greybird Arnaud TAMAILLON added a comment -

          I tested this script with latest plugin version

          pipeline {
            agent any
            stages {
              stage('Build') {
                steps {
                  bat 'exit 1;'
                }
              }
            }
            post {
              always {
                step([$class: 'ClaimPublisher'])
              }
            }
          }

          And it works.

          Can you confirm issue is still present?

          Show
          greybird Arnaud TAMAILLON added a comment - I tested this script with latest plugin version pipeline { agent any stages { stage( 'Build' ) { steps { bat 'exit 1;' } } } post { always { step([$class: 'ClaimPublisher' ]) } } } And it works. Can you confirm issue is still present?
          Hide
          macdrega Joerg Schwaerzler added a comment -

          Hi, looks like for the declarative pipeline everything works just fine. For the scripted pipeline you'll need to add some lines of code, esp. in case you want to claim your job in case an exception happened. You may do something like. Unfortunately you won't be able to catch exceptions outside withClaim to keep the build status SUCCESS. But catching your exceptions still can be done inside withClaim.

          def withClaim(Closure closure) {
            try {
            closure()
            node {
              // workaround for older Jenkins / claim plugin versions. Won't need the following line in latest Jenkins.
              currentBuild.result = currentBuild.currentResult
              step([$class: 'ClaimPublisher'])
            }
          } catch (Exception err) {
            currentBuild.result = "FAILURE"
            node {
              step([$class: 'ClaimPublisher'])
            }
            throw err
           }
          }
          
          withClaim {
            echo currentBuild.result
            < your code >
            currentBuild.result = 'UNSTABLE'
            // currentBuild.result = 'FAILURE'
            // error "Failed"
          }
          
          Show
          macdrega Joerg Schwaerzler added a comment - Hi, looks like for the declarative pipeline everything works just fine. For the scripted pipeline you'll need to add some lines of code, esp. in case you want to claim your job in case an exception happened. You may do something like. Unfortunately you won't be able to catch exceptions outside withClaim to keep the build status SUCCESS . But catching your exceptions still can be done inside withClaim. def withClaim(Closure closure) { try { closure() node { // workaround for older Jenkins / claim plugin versions. Won't need the following line in latest Jenkins. currentBuild.result = currentBuild.currentResult step([$class: 'ClaimPublisher' ]) } } catch (Exception err) { currentBuild.result = "FAILURE" node { step([$class: 'ClaimPublisher' ]) } throw err } } withClaim { echo currentBuild.result < your code > currentBuild.result = 'UNSTABLE' // currentBuild.result = 'FAILURE' // error "Failed" }
          Hide
          lostinberlin Steve Boardwell added a comment -

          As a side note, the ClaimPublisher step needs a node to work meaning it will fail if you are

          • using the declarative pipeline
          • using stage-based agents (setting agent none under the global pipeline declaration)

          you will need to put the step in a node closure

          pipeline {
            agent none
            stages {
              stage('Build') {
                agent any
                steps {
                  bat 'exit 1;'
                }
              }
            }
            post {
              always {
                // need the node closure here because agent none was set above
                node {
                  step([$class: 'ClaimPublisher'])
                }
              }
            }
          }
          
          Show
          lostinberlin Steve Boardwell added a comment - As a side note, the ClaimPublisher  step needs a node to work meaning it will fail if you are using the declarative pipeline using stage-based agents (setting agent none under the global pipeline declaration) you will need to put the step in a node closure pipeline { agent none stages { stage('Build') { agent any steps { bat 'exit 1;' } } } post { always { // need the node closure here because agent none was set above node { step([$class: 'ClaimPublisher']) } } } }

            People

            • Assignee:
              greybird Arnaud TAMAILLON
              Reporter:
              ssbarnea Sorin Sbarnea
            • Votes:
              15 Vote for this issue
              Watchers:
              18 Start watching this issue

              Dates

              • Created:
                Updated: