[JIRA] (JENKINS-41519) Post stages should have well defined order

3 views
Skip to first unread message

rpocase@gmail.com (JIRA)

unread,
Jan 27, 2017, 10:57:04 AM1/27/17
to jenkinsc...@googlegroups.com
Robby Pocase created an issue
 
Jenkins / Improvement JENKINS-41519
Post stages should have well defined order
Issue Type: Improvement Improvement
Assignee: Andrew Bayer
Components: pipeline-model-definition-plugin
Created: 2017/Jan/27 3:56 PM
Priority: Major Major
Reporter: Robby Pocase

Post stages currently have a defined order in which they run. This limits certain use cases (especially in regards to clean up procedures). It would be nice to be able to specify certain post stages have to run before others.

Jenkinsfile
pipeline {
  agent { label 'label' }
  stages {
    stage('stage') {     
      steps {
        echo "stage"
      }
      post {
        success {
          echo "Success"
        }
        always {
            echo "Always"
            //deleteDir()
        }
      }
    }
  }
}
[Pipeline] {
[Pipeline] stage
[Pipeline] { (stage)
[Pipeline] echo
stage
[Pipeline] echo
Post stage
[Pipeline] echo
Always
[Pipeline] echo
Success
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

In the example Jenkinsfile, I want success to run before always. In my production use case, I want to stash some artifacts for a future stage. The future stage is set up to run on certain conditions, so clean up cannot be delayed.

How order should be determined is open ended. To me, running in the Jenkinsfile order is more intuitive for a user, but there may be cases where you want to change that.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

ericdnelson@gmail.com (JIRA)

unread,
Feb 28, 2018, 6:10:05 PM2/28/18
to jenkinsc...@googlegroups.com
Eric Nelson commented on Improvement JENKINS-41519
 
Re: Post stages should have well defined order

Either a user definable order or a LAST concept would be good. I tried to use always to cleanup the workspace and put a few artifact gathering steps in success and was quite confused for a bit why artifacts were not getting archived.  

This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

ikobh7@gmail.com (JIRA)

unread,
Mar 7, 2018, 4:00:06 AM3/7/18
to jenkinsc...@googlegroups.com
IKO BH updated an issue
 
Change By: IKO BH
Attachment: image-2018-03-07-10-58-26-892.png

ikobh7@gmail.com (JIRA)

unread,
Mar 7, 2018, 4:09:01 AM3/7/18
to jenkinsc...@googlegroups.com
IKO BH commented on Improvement JENKINS-41519
 
Re: Post stages should have well defined order

Using the following in my Jenkinsfile:

    stage('Test') {
      steps {
        sh 'pytest --junitxml result.xml testing/'
      }
      post {
        failure {
          mail(to: 'us...@example.com', subject: "Failed Pipeline : ${currentBuild.fullDisplayName}", body: "Something is wrong with ${env.BUILD_URL}")
        }
        always {
          junit 'result.xml'
        }

When one of my test fails, I get the following indication:

But the mail is being sent successfully.

When moving the 'post' section to be under 'pipline' section, or when deleting the 'always' block,leaving only the 'failure' block, Mail section is green.

You think the order of block execution within the 'post' section has an impact on the GUI presented?

As I mentioned, the Mail step doesn't actually fails, it actually send an email as it should. But GUI indicates a failure.

 

Any thoughts?

 

jgrant216@gmail.com (JIRA)

unread,
Mar 23, 2018, 12:53:02 PM3/23/18
to jenkinsc...@googlegroups.com
Jeff G commented on Improvement JENKINS-41519

+1 for this.  Just got bit because you can't use archiveArtifacts in a post:success if you use cleanWs in post:always because post:always will clean up the artifacts you want to archive.

andrew.bayer@gmail.com (JIRA)

unread,
Apr 3, 2018, 4:08:08 PM4/3/18
to jenkinsc...@googlegroups.com

I think I have something that may help with this over in a PR for JENKINS-41239 - a new post condition, currently called cleanup (because I couldn't call it finally due to that being a reserved word in Groovy), which is like always (as in it'll run regardless of build status), but it runs after all other post conditions. So with this, always is the first post condition to run, and cleanup is the last, regardless of build status. So you can do things like deleteDir() etc in cleanup without problems.

Does that sound like it'd do the trick here?

stefan.thurnherr@gmail.com (JIRA)

unread,
Apr 3, 2018, 4:18:02 PM4/3/18
to jenkinsc...@googlegroups.com

Andrew Bayer +1 for the cleanup condition, would solve this issue for us since we mostly want to delete workspace

ericdnelson@gmail.com (JIRA)

unread,
Apr 3, 2018, 5:10:02 PM4/3/18
to jenkinsc...@googlegroups.com

Andrew Bayer +1 for cleanup here as well. Solves the issue in most use cases I had in mind.  Thanks! 

fnasser@redhat.com (JIRA)

unread,
Sep 18, 2018, 3:58:02 PM9/18/18
to jenkinsc...@googlegroups.com

Caught by surprise with always not being the last one (it is sort of equivalent to the java finally which runs last, for the same cleanup reasons brought up in several JIRAs).  But cleanup would work around that (/me still prefers always being last).

Do we have a JIRA for the 'cleanup' addition yet?  Could not find with JIRA search as the word is too common.

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

stefan.thurnherr@gmail.com (JIRA)

unread,
Sep 18, 2018, 4:04:03 PM9/18/18
to jenkinsc...@googlegroups.com

Fernando Nasser Have you read the earlier comments in this jira issue? You'll find the jira issue for the 'cleanup' addition in Andrew's comment

fnasser@redhat.com (JIRA)

unread,
Sep 19, 2018, 9:17:03 AM9/19/18
to jenkinsc...@googlegroups.com

Thanks Stefan, not sure how I missed the JENKINS-41239 one.

 

andrew.bayer@gmail.com (JIRA)

unread,
Nov 5, 2018, 10:52:03 AM11/5/18
to jenkinsc...@googlegroups.com
Andrew Bayer updated Improvement JENKINS-41519
 

I think this is clear enough now. =)

Change By: Andrew Bayer
Status: Open Fixed but Unreleased
Resolution: Fixed

fnasser@redhat.com (JIRA)

unread,
Nov 5, 2018, 3:02:02 PM11/5/18
to jenkinsc...@googlegroups.com
 
Re: Post stages should have well defined order

 is.  Many thanks for taking care of this Andrew.

P.S.: Accordingly to JENKINS-41239  it has been released in Declarative 1.2.9.  But this Jira says fixed-but-unreleased...

 

andrew.bayer@gmail.com (JIRA)

unread,
Nov 5, 2018, 3:10:05 PM11/5/18
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Nov 5, 2018, 3:10:05 PM11/5/18
to jenkinsc...@googlegroups.com
Andrew Bayer commented on Improvement JENKINS-41519
 
Re: Post stages should have well defined order

Blech, our statuses are annoying. Fixing up.

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:25:14 PM10/22/19
to jenkinsc...@googlegroups.com
Liam Newman closed an issue as Fixed
 

Bulk closing resolved issues.

Change By: Liam Newman
Status: Resolved Closed
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages