-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
74 lines (60 loc) · 2.96 KB
/
Jenkinsfile
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
pipeline {
agent any
environment {
TELEGRAM_TOKEN = credentials("Telegram-Token")
TELEGRAM_ID = credentials("Telegram-ID")
GIT_COMMIT_MESSAGE = sh(returnStdout: true, script: "git log -n 1 --format=%s ${GIT_COMMIT}").trim()
GIT_COMMIT_SHORT = sh(returnStdout: true, script: "git rev-parse --short ${GIT_COMMIT}").trim()
BUILD_READY = "${JOB_NAME}에서 새로운 커밋 감지. ${GIT_BRANCH} 브랜치의 ${GIT_COMMIT_MESSAGE}(${GIT_COMMIT_SHORT}) 커밋에 대한 빌드를 준비중입니다."
BUILD_START = "${GIT_BRANCH} 브랜치의 ${GIT_COMMIT_MESSAGE}(${GIT_COMMIT_SHORT}) 커밋에 대한 빌드를 시작합니다."
BUILD_PUSH = "${GIT_BRANCH} 브랜치의 ${GIT_COMMIT_MESSAGE}(${GIT_COMMIT_SHORT}) 커밋에 대한 빌드를 푸시합니다."
BUILD_SUCCESS = "${JOB_NAME}의 새로운 빌드를 정상적으로 완료하였습니다."
BUILD_FAILURE = "${JOB_NAME}의 새로운 빌드를 실패하였습니다."
}
triggers {
cron('H H * * 0')
pollSCM('* * * * *')
}
stages {
stage("Set") {
steps {
script {
DOCKERHUB_CREDENTIAL = "Docker-Hub"
DOCKER_IMAGE_NAME = "cups"
DOCKER_IMAGE_STORAGE = "dohun0310"
DOCKER_IMAGE_TAG = "latest"
VERSION = new Date().format("yyyy-MM-dd")
sh "curl --location --request POST 'https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage' --form text='${BUILD_READY}' --form chat_id='${TELEGRAM_ID}'"
sh "docker run --privileged --rm tonistiigi/binfmt --install all"
}
}
}
stage("Build") {
steps {
script {
docker.withRegistry("https://index.docker.io/v1/", DOCKERHUB_CREDENTIAL) {
sh "curl --location --request POST 'https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage' --form text='${BUILD_START}' --form chat_id='${TELEGRAM_ID}'"
sh "docker buildx ls | grep mybuilder && docker buildx rm mybuilder || true"
sh "docker buildx create --name mybuilder --driver docker-container"
sh "docker buildx inspect mybuilder --bootstrap"
sh "docker buildx use mybuilder"
sh "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t ${DOCKER_IMAGE_STORAGE}/${DOCKER_IMAGE_NAME}:${VERSION} -t ${DOCKER_IMAGE_STORAGE}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} --push ."
sh "curl --location --request POST 'https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage' --form text='${BUILD_PUSH}' --form chat_id='${TELEGRAM_ID}'"
}
}
}
}
}
post {
success {
script {
sh "curl --location --request POST 'https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage' --form text='${BUILD_SUCCESS}' --form chat_id='${TELEGRAM_ID}'"
}
}
failure {
script {
sh "curl --location --request POST 'https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage' --form text='${BUILD_FAILURE}' --form chat_id='${TELEGRAM_ID}'"
}
}
}
}