Jenkins

Aus Alexander's Wiki

Pipeline

Script-Anfang

#!groovy
pipeline {
    agent {
        label 'ec2-fleet'
    }
    environment {
        AWS_CREDS = credentials('AWS Jenkins')
        EMAIL_TO = 'me@example.com'
    }
    options {
        buildDiscarder(logRotator(artifactNumToKeepStr: '10', numToKeepStr: '10'))
    }

Git-Checkout

    stages {
        stage("GIT Checkout") {
            parallel {
                stage('Checkout for Multibranch Pipeline') {
                    when {
                        allOf {
                            expression { env.repositoryNames == null }
                        }
                    }
                    steps {
                        checkout scm

//                is equivalent
//                checkout([
//                        $class                           : 'GitSCM',
//                        branches                         : scm.branches,
//                        doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
//                        extensions                       : scm.extensions,
//                        userRemoteConfigs                : scm.userRemoteConfigs
//                ])


                    }
                }

Post-Declaration

    post {
        always {
            echo "This block always runs."
        }
        changed {
            echo "This block runs when the current status is different than the previous one."
        }
        fixed {
            echo "This block runs when the current status is success and the previous one was failed or unstable."
        }
        regression {
            echo "This block runs when the current status is anything except success but the previous one was successful."
        }
        unstable {
            echo "This block runs if the current status is marked unstable."
        }
        aborted {
            echo "This block runs when the build process is aborted."
        }
        failure {
            echo "This block runs when the build is failed."
        }
        success {
            echo "This block runs when the build is succeeded."
        }
        unsuccessful {
            echo "This block runs when the current status is anything except success."
        }
        cleanup {
            echo "This block always runs after other conditions are evaluated."
        }
    }