-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
127 lines (114 loc) · 3.74 KB
/
Jenkinsfile
File metadata and controls
127 lines (114 loc) · 3.74 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
pipeline {
environment {
repository = "dls3145/camandedit"
DOCKERHUB_CREDENTIALS = credentials('docker-hun-jo')
dockerImage = ""
dockerTag = "1.0"
TargetServer ="backend-server"
SLACK_NAME = "camandedit"
SLACK_TOKEN = "slack-noti-key"
SLACK_CHANNEL = "#jenkins-ci"
}
agent any
stages {
stage("prepare"){
steps {
slackSend (channel: SLACK_CHANNEL, color: "#33FF33", message: "Deploy Start \n ", teamDomain: SLACK_NAME, tokenCredentialId: SLACK_TOKEN)
git branch : "develop",
credentialsId : "jenkins-pk",
url: "git@github.com:TeamDiligence/CamAndEdit_Back.git"
sh "pwd"
sh "cat $HOME/envfile/.env > .production.env"
}
post {
success {
echo "prepare Success"
sh "ls -al"
}
failure {
echo "prepare fail!"
}
}
}
stage("docker build"){
steps {
script {
sh "echo 'docker build' "
dockerImage = docker.build repository + ":$dockerTag"
}
}
post {
success {
echo "docker build Success"
}
failure {
echo "docker build faile"
}
}
}
stage("docker login"){
steps {
script {
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
}
}
}
stage("docker push"){
steps {
script {
sh "docker push $repository:$dockerTag"
}
}
post {
success {
echo "docker push Success"
}
failure {
echo "docker push faile"
}
}
}
stage("send deployfile"){
steps {
script {
sshPublisher(
continueOneError: false, failOnError: true,
publishers: [
sshPublisherDesc(
configName: "${TargetServer}",
verbose: true,
transfers : [
sshTransfer(sourceFiles: "deploy.sh"),
sshTransfer(execCommand: "sh deploy.sh")
]
)
]
)
}
}
}
stage("docker clean up"){
steps {
script {
sh "docker rmi -f $repository:$dockerTag"
}
}
post {
success {
echo "docker clean Up Success"
}
failure {
echo "docker cleanUp faile"
}
}
}
}
post {
success {
slackSend (channel: SLACK_CHANNEL, color: "#33FF33", message: "Deploy Success \n ", teamDomain: SLACK_NAME, tokenCredentialId: SLACK_TOKEN)
}
failure {
slackSend (channel: SLACK_CHANNEL, color: "#FF0000", message: "Deploy failure \n ", teamDomain: SLACK_NAME, tokenCredentialId: SLACK_TOKEN)
}
}
}