Chris Pomeroy
2023-06-11 afa76d0a20f3863767629d4f0029244377926aeb
1
2
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def customImage
def discordUrl = "https://discordapp.com/api/webhooks/764667082272145418/vorf2JdFG47WAmQP3yZhgHH12wW_qUXG0bS0SG8INLYVwU0HcDFajq9doaDgi_hnI00-"
def scmvars
 
 
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}","--no-cache .")
                }
            }
            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}"
                }
            }
        }
    }
    post{
        success {
            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 ${JOB_NAME} docker image.\nPlease review the build", footer: "Jenkins docker image", link: "${env.BUILD_URL}", title: "${JOB_NAME}", result: "${currentBuild.currentResult}", webhookURL: "${discordUrl}"
        }
    }
}