yu.pitomets
yu.pitomets

Reputation: 1840

Jenkins multibranch pipeline post build actions

How to define post build actions for Jenkins multi pipeline project?

There is a separate option available when you have a simple project but not for multipipeline.

enter image description here

Upvotes: 1

Views: 5782

Answers (2)

bp2010
bp2010

Reputation: 2462

To add post build steps to a Multibranch Pipeline, you need to code these steps into the finally block, an example is below:

node {

    try {
        stage("Checkout") {
            // checkout scm
        }

        stage("Build & test") {
            // build & Unit test
        }
    } catch (e) {
        // fail the build if an exception is thrown
        currentBuild.result = "FAILED"
        throw e
    } finally {
        // Post build steps here
        /* Success or failure, always run post build steps */
        // send email
        // publish test results etc etc
    }
}

For most of the post-build steps you would want there are online examples of them on how to write in pipeline format. If you have any specific one please list it here

Upvotes: 4

Itai Ganot
Itai Ganot

Reputation: 6305

When you write a pipeline, you describe the whole flow yourself, which gives you great flexibility to do whatever you want, including running post-build steps.

You can see an example of using post-build steps in a pipeline I wrote:

https://github.com/geek-kb/Android_Pipeline/blob/master/Jenkinsfile

Example from that code:

run_in_stage('Post steps', {
    sh """
        # Add libCore.so files to symbols.zip
        find ${cwd}/Product-CoreSDK/obj/local -name libCore.so | zip -r ${cwd}/Product/build/outputs/symbols.zip -@
        # Remove unaligned apk's
        rm -f ${cwd}/Product/build/outputs/apk/*-unaligned.apk
    """
})

Upvotes: 0

Related Questions