Chris Pomeroy
2020-10-11 d4fc454a7829aaa983e1afca62f66feb09494490
Added discord notifications to the builds
1 files modified
46 ■■■■ changed files
Jenkinsfile 46 ●●●● patch | view | raw | blame | history
Jenkinsfile
@@ -1,14 +1,22 @@
node('pi-docker-agent') {
    def customImage
    def discordUrl = "https://discordapp.com/api/webhooks/764667082272145418/vorf2JdFG47WAmQP3yZhgHH12wW_qUXG0bS0SG8INLYVwU0HcDFajq9doaDgi_hnI00-"
    def BUILDDATE = sh(script: "echo `date --rfc-3339=date`", returnStdout: true).trim()
    stage ('Checkout source'){
        checkout scm
    }
    
    stage ('Build image'){
        //Build the image
        customImage = docker.build("jenkins:${BUILDDATE}-build-${env.BUILD_ID}")
    stage ('Build image'){
        steps {
            //Build the image
            customImage = docker.build("jenkins:${BUILDDATE}-build-${env.BUILD_ID}")
        }
        post {
            failure {
                discordSend description:" Building image failed ", footer: "Jenkins docker image", link: "${env.BUILD_URL}", title: "${JOB_NAME}", result: "${currentBuild.currentResult}", webhookURL: "${discordUrl}"
            }
        }
    }
    // stage('Test Image'){
    //     options 
@@ -17,9 +25,35 @@
    //     }
    // }
    stage('Push Image'){
        docker.withRegistry('https://dev-reg.darkurthe.net'){
            customImage.push()
            customImage.push("latest")
        steps {
            docker.withRegistry('https://dev-reg.darkurthe.net'){
                customImage.push()
                customImage.push("latest")
            }
        }
        post {
            failure {
                discordSend description: " Pushing image failed ", footer: "Jenkins docker image", link: "${env.BUILD_URL}", title: "${JOB_NAME}", result: "${currentBuild.currentResult}", webhookURL: "${discordUrl}"
            }
        }
    }
    stage('Deploy Image'){
        steps {
            sh "docker service update --force --image dev-reg.darkurthe.net/jenkins:${BUILDDATE}-build-${env.BUILD_ID}"
        }
        post {
            failure {
                discordSend description: " Deploying image failed ", footer: "Jenkins docker image", link: "${env.BUILD_URL}", title: "${JOB_NAME}", result: "${currentBuild.currentResult}", webhookURL: "${discordUrl}"
            }
        }
    }
    post {
        success {
            discordSend description: " New Jenkins image has been deployed ", footer: "Jenkins docker image", link: "${env.BUILD_URL}", title: "${JOB_NAME}", result: "${currentBuild.currentResult}", webhookURL: "${discordUrl}"
        }
        unsuccessful{
            discordSend description: " There was a problem with the Jenkins docker image.\nPlease review the build", footer: "Jenkins docker image", link: "${env.BUILD_URL}", title: "${JOB_NAME}", result: "${currentBuild.currentResult}", webhookURL: "${discordUrl}"
        }
    }
}