[JIRA] (JENKINS-56683) Declarative Pipeline: set the build result when tests fail without a script block

2 views
Skip to first unread message

bochenski.kuba+jenkins@gmail.com (JIRA)

unread,
Mar 22, 2019, 10:40:03 AM3/22/19
to jenkinsc...@googlegroups.com
Jakub Bochenski created an issue
 
Jenkins / Improvement JENKINS-56683
Declarative Pipeline: set the build result when tests fail without a script block
Issue Type: Improvement Improvement
Assignee: Andrew Bayer
Components: pipeline-model-definition-plugin
Created: 2019-03-22 14:39
Priority: Major Major
Reporter: Jakub Bochenski

pipeline {

    agent any

    stages {
        stage ('Build & Test') {
            steps {
                sh 'echo Building... Failure here will fail the build'
                script {
                    try {
                        echo 'Running tests...'
                        sh 'exit 1'
                    }
                    catch (exc) {
                        echo 'Testing failed!'
                        currentBuild.result = 'UNSTABLE'
                    }
                }
            }
        }
    }
}

E.g. as described here https://lastviking.eu/how_to_set_result_as_unstable_from_declarative_pipeline.html

It would be nice to have a way to set result to unstable without having to use `script` or a framework specific publisher plugin (e.g. junit plugin)

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

bochenski.kuba+jenkins@gmail.com (JIRA)

unread,
May 31, 2019, 10:58:03 AM5/31/19
to jenkinsc...@googlegroups.com
Jakub Bochenski commented on Improvement JENKINS-56683
 
Re: Declarative Pipeline: set the build result when tests fail without a script block

Devin Nusbaum does the new `unstable` step solve this? I think it still requires a `script` block, right?

dnusbaum@cloudbees.com (JIRA)

unread,
May 31, 2019, 11:02:02 AM5/31/19
to jenkinsc...@googlegroups.com

Jakub Bochenski From a quick glance, you should be able to use warnError, which we added specifically so it could be used in Declarative without a script block:

Change this code:

script {
  try {
    echo 'Running tests...'
    sh 'exit 1'
  }
  catch (exc) {
    echo 'Testing failed!'
    currentBuild.result = 'UNSTABLE'
  }
}

to this:

warnError('Testing Failed!') {
  echo 'Running tests...'
  sh 'exit 1'
}

bochenski.kuba+jenkins@gmail.com (JIRA)

unread,
May 31, 2019, 11:54:02 AM5/31/19
to jenkinsc...@googlegroups.com
Jakub Bochenski resolved as Duplicate
 

That's great. I think we can resolve this issue now

Change By: Jakub Bochenski
Status: Open Resolved
Resolution: Duplicate

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:19:03 PM10/22/19
to jenkinsc...@googlegroups.com
Liam Newman closed an issue as Duplicate
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