Jenkinsfile 1.08 KB
Newer Older
1
pipeline {
João Lino's avatar
João Lino committed
2
    def customImage
3 4 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 33 34 35 36 37 38 39 40 41 42 43
    agent {
        node {
            label 'docker'
        }
    }
    options {
        timeout(time: 1, unit: 'HOURS')
        buildDiscarder(
            logRotator(
                numToKeepStr: '10',
                artifactNumToKeepStr: '3'
            )
        )
        ansiColor('xterm')
    }
    triggers {
        cron('@weekly')
    }
    stages {
        stage('Clone repository') {
            checkout scm
        }
        stage('Build Docker image') {
            customImage = docker.build("demo-infra-jenkins-agent")
        }
        stage('Test Docker image') {
            app.inside {
                sh 'mvn'
            }
        }
        stage('Push image') {
            /* push image with two tags:
             *  - the incremental build number from Jenkins;
             *  - the 'latest' tag. */
            docker.withRegistry('https://www.joaolino.com/nexus/repository/docker-public/', 'nexus-admin') {
                customImage.push("${env.BUILD_NUMBER}")
                customImage.push("latest")
            }
        }
    }
}