-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile_PRD
88 lines (87 loc) · 2.97 KB
/
Jenkinsfile_PRD
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
// 전역변수 설정
//dockerImage는 비워두기
//registryCredential은 ecr에 접근할 젠킨스내 secret
pipeline {
environment {
registry = ""
imagename = ""
registryCredential = ''
slackchannel = ''
projectrepo = ''
deployrepo = ''
deployreponame = ''
deployrepoappname = ''
dockerImage = ''
}
agent any
stages {
stage('Cloning Git') {
steps {
slackSend (channel: slackchannel, color: '#00FF00', message: "${env.JOB_NAME}앱의 CI 과정이 시작되었습니다 \n Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
git([url: projectrepo, branch: 'master', credentialsId: 'sshkey'])
}
}
stage('Building Image') {
steps{
script {
dockerImage = docker.build "$registry/$imagename:$BUILD_NUMBER"
}
}
}
stage('Testing') {
steps{
script {
dockerImage.inside {
sh 'node --version'
}
}
}
}
stage('Push Image') {
steps{
script {
docker.withRegistry( "https://$registry", registryCredential ) {
dockerImage.push()
}
}
}
}
stage('Cleaning Up') {
steps{
sh "docker rmi $registry/$imagename:$BUILD_NUMBER"
}
}
stage('Deploy') {
steps {
dir(deployreponame) {
git([url: deployrepo, branch: 'master', credentialsId: 'sshkey'])
}
dir (deployreponame) {
sh "sed -i 's/$imagename:.*\$/$imagename:${env.BUILD_NUMBER}/g' $deployrepoappname/deployment.yaml"
sh "git add $deployrepoappname/deployment.yaml"
sh "git commit -m 'updated the image tag to ${env.BUILD_NUMBER}'"
sh 'git push --set-upstream origin master'
}
}
}
}
post {
always {
echo 'One way or another, I have finished'
}
success {
slackSend (channel: slackchannel, color: '#00FF00', message: "빌드 완료 \n ${env.JOB_NAME}앱의 CI 과정이 성공적으로 끝났습니다 \n Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
unstable {
echo 'I am unstable 11hook tst/'
}
failure {
deleteDir()
slackSend (channel: slackchannel, color: '#00FF00', message: "빌드가 실패하였습니다 \n ${env.JOB_NAME}앱의 젠킨스 콘솔을 확인해주세요 \n Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
slackSend (channel: '#devops-alarm', color: '#00FF00', message: "빌드가 실패하였습니다 \n ${env.JOB_NAME}앱의 젠킨스 콘솔을 확인해주세요 \n Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
changed {
echo 'Things were different before...'
}
}
}