Chris Pomeroy
2021-04-04 d8f496921223a923d81454b3c7429efb66c9c1f0
Jenkinsfile
@@ -1,59 +1,62 @@
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()
def customImage
def discordUrl = "https://discordapp.com/api/webhooks/764667082272145418/vorf2JdFG47WAmQP3yZhgHH12wW_qUXG0bS0SG8INLYVwU0HcDFajq9doaDgi_hnI00-"
    stage ('Checkout source'){
        checkout scm
    }
    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
    //     customImage.inside {
    //         sh 'curl -s -o /dev/null -w "%{http_code}" localhost:8080/login'
    //     }
    // }
    stage('Push Image'){
        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}"
pipeline{
    agent{
        label "x86-docker-agent"
    }
    environment{
        def BUILDDATE = sh(script: "echo `date --rfc-3339=date`", returnStdout: true).trim()
    }
    stages{
        stage ('Checkout source'){
            steps{
                checkout scm
            }
            post{
                failure {
                    discordSend description:"${env.STAGE_NAME} failed code for ${JOB_NAME}", footer: "Jenkins docker image", link: "${env.BUILD_URL}", title: "${JOB_NAME}", result: "${currentBuild.currentResult}", webhookURL: "${discordUrl}"
                }
            }
        }
        stage ('Build image'){
            steps{
                script{
                    customImage = docker.build("${JOB_NAME}:${BUILDDATE}-build-${env.BUILD_ID}")
                }
            }
            post{
                failure {
                    discordSend description:"${env.STAGE_NAME} for failed ${JOB_NAME}", footer: "Jenkins agent docker image", link: "${env.BUILD_URL}", title: "${JOB_NAME}", result: "${currentBuild.currentResult}", webhookURL: "${discordUrl}"
                }
            }
        }
        stage('Push Image'){
           steps{
               script{
                    docker.withRegistry('https://dev-reg.darkurthe.net'){
                        customImage.push()
                        customImage.push("latest")
                    }
               }
            }
            post{
                failure {
                    discordSend description: "${env.STAGE_NAME} failed for ${JOB_NAME}", footer: "Jenkins agent docker image", link: "${env.BUILD_URL}", title: "${JOB_NAME}", result: "${currentBuild.currentResult}", webhookURL: "${discordUrl}"
                }
            }
        }
        stage('Deploy service to dev'){
        }
    }
    post {
    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}"
            discordSend description: " New ${JOB_NAME}:${BUILDDATE}-build-${env.BUILD_ID} image has been pushed to the registry ", 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}"
            discordSend description: " There was a problem with the ${JOB_NAME} docker image.\nPlease review the build", footer: "Jenkins docker image", link: "${env.BUILD_URL}", title: "${JOB_NAME}", result: "${currentBuild.currentResult}", webhookURL: "${discordUrl}"
        }
    }
}