This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Jenkinsfile
74 lines (61 loc) · 2.61 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
tools {
maven "Maven 3.6.3"
}
environment {
GIT_COMMIT_REV=''
GIT_CHANGE_BRANCH_NAME=''
GIT_COMMIT_SHA=''
}
options {
skipDefaultCheckout()
}
stages {
stage('git checkout & clone') {
steps {
script {
cleanWs()
GIT_CHANGE_BRANCH_NAME = sh(returnStdout: true, script: 'echo ${payload} | python3 -c \"import sys,json;print(json.load(sys.stdin,strict=False)[\'ref\'][11:])\"').trim()
GIT_COMMIT_SHA = sh(returnStdout: true, script: 'echo ${payload} | python3 -c \"import sys,json;print(json.load(sys.stdin,strict=False)[\'head_commit\'][\'id\'])\"').trim()
echo "arrive ${GIT_CHANGE_BRANCH_NAME}"
sh "git clone -b ${GIT_CHANGE_BRANCH_NAME} --single-branch \"https://github.com/f-lab-edu/make-delivery.git\""
}
}
}
stage('Build') {
steps {
sh "mvn -f make-delivery/pom.xml -DskipTests clean package"
archiveArtifacts 'make-delivery/target/*.jar'
}
post {
success {
sh ("curl -X POST -H \"Content-Type: application/json\" \
--data '{\"state\": \"success\", \"context\": \"@@pass ci test & build\", \"target_url\": \"http://115.85.180.192:8080/job/make-delivery\"}' \
\"https://${GITHUB_TOKEN}@api.github.com/repos/f-lab-edu/make-delivery/statuses/${GIT_COMMIT_SHA}\"")
}
failure {
sh ("curl -X POST -H \"Content-Type: application/json\" \
--data '{\"state\": \"failure\", \"context\": \"@@failure ci test & build\", \"target_url\": \"http://115.85.180.192:8080/job/make-delivery\"}' \
\"https://${GITHUB_TOKEN}@api.github.com/repos/f-lab-edu/make-delivery/statuses/${GIT_COMMIT_SHA}\"")
}
}
}
stage('Dockerfile Build & Push To Docker Hub & Delete Docker Image') {
steps {
script {
sh "docker build -t tjdrnr05571/make-delivery make-delivery/."
sh "docker push tjdrnr05571/make-delivery"
sh "docker rmi tjdrnr05571/make-delivery"
}
}
}
stage('Deploy') {
steps {
script {
sh "ssh -p 1039 root@106.10.53.113 -T sh < /var/lib/jenkins/docker-deploy.sh"
}
}
}
}
}