Jenkinsfile 3.13 KB
Newer Older
1
pipeline {
João Lino's avatar
João Lino committed
2 3
    agent {
        node {
João Lino's avatar
João Lino committed
4
            label 'docker'
João Lino's avatar
João Lino committed
5 6 7
            }
        }
    }
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
    parameters {
        booleanParam(
            name: 'SNYK_TEST',
            defaultValue: true,
            description: 'Do you want to run Snyk tests?'
        )
        booleanParam(
            name: 'RELEASE_INPUT',
            defaultValue: false,
            description: 'Do you want to release this version? (Only relevant if branch is master or release/*)'
        )
    }
    options {
        timeout(time: 1, unit: 'HOURS')
        buildDiscarder(
            logRotator(
                numToKeepStr: '10',
                artifactNumToKeepStr: '3'
            )
        )
        ansiColor('xterm')
    }
    triggers {
        cron('@weekly')
    }
33
    stages {
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
        stage('Checkout') {
            agent {
                label 'docker'
            }
            steps {
                checkout scm
                sh 'git fetch --prune --tags'
            }
        }
        stage('Verify') {
            agent {
                label 'docker'
            }
            steps {
                sh 'mvn clean verify'
            }
        }
        stage('Snyk test') {
            agent {
                label 'docker'
            }
            when {
                expression { return params.SNYK_TEST }
            }
            steps {
                sh 'mvn snyk:test'
            }
        }
62 63 64 65 66
        stage('Deploy') {
            agent {
                label 'docker'
            }
            when {
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
                anyOf {
                    branch 'master'
                    branch pattern: 'release/*'
                }
                not {
                    expression { return params.RELEASE_INPUT }
                }
            }
            steps {
                sh 'mvn deploy'
            }
        }
        stage('Snyk monitor') {
            agent {
                label 'docker'
            }
            when {
                anyOf {
                    branch 'master'
                    branch pattern: 'release/*'
                }
                expression { return params.SNYK_TEST }
            }
            steps {
                sh 'mvn snyk:monitor'
            }
        }
        stage('Release') {
            agent {
                label 'docker'
            }
            when {
                allOf {
                    anyOf {
                        branch 'master'
                        branch pattern: 'release/*'
                    }
                    expression { return params.RELEASE_INPUT }
                }
            }
            environment {
                RELEASE_VERSION = sh(
                    returnStdout: true,
                    script: 'mvn help:evaluate -Dexpression=project.version -q -DforceStdout'
                ).trim().replace('-SNAPSHOT','')
112 113
            }
            steps {
114 115 116 117 118 119
                sh "git checkout ${BRANCH_NAME}"
                sh 'mvn release:prepare release:perform -V'
                script {
                    currentBuild.description = "Release ${RELEASE_VERSION}"
                    currentBuild.keepLog = true
                }
120 121 122 123
            }
        }
    }
}