Job DSL - How to configure postBuildSteps for maven to run only if the build is successful

Is there a way to set dsl to configure postBuildSteps only if the build is successful, for a maven job. I saw that there is postSuccessfulBuildSteps, which applies only to the release order.

+4
source share
3 answers

You must use the "configure" block to add "custom" <runPostStepsIfResult>settings to the config.xml file

This works for me:

job(type: Maven) {
    name('MyMavenJob')
    goals('install')

    preBuildSteps {
        shell('#!/bin/bash\n' +
              'echo "PRE BUILD SCRIPT"\n' +
              'env | sort\n' +
              'echo "PRE BUILD END"\n')
    }

    postBuildSteps {
        shell('#!/bin/bash\n' +
              'echo "POST BUILD SCRIPT"\n' +
              'env | sort\n' +
              'echo "POST BUILD END"\n')
    }

    // Append <runPostStepsIfResult> at the end of the xml
    //    (which will be just after the closing </postbuilders> tag)
    // "it" is a groovy.util.Node representing the
    //    root <project> element of config.xml.
    configure { it <<
        'runPostStepsIfResult' {
            name('SUCCESS')
        }
    }
}

, XML, Job DSL, , , Jenkins, config.xml Jenkins-master, ${JENKINS_HOME}/jobs/job-name/config.xml

job-dsl http://job-dsl.herokuapp.com/ , , , job/job-name/config.xml .

+4

:

postBuildSteps("SUCCESS") {
    ...
}
+1

All Articles