-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
87 lines (78 loc) · 2.2 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
75
76
77
78
79
80
81
82
83
84
85
86
87
pipeline {
agent any
parameters {
string name: 'IMAGE_NAME', defaultValue: 'news-write-server'
string name: 'IMAGE_REGISTRY_ACCOUNT', defaultValue: 'hahajong'
}
stages {
stage('Test Gradle Project') {
steps {
sh './gradlew test --no-daemon'
}
}
stage('Build Gradle Project') {
steps {
sh './gradlew build -x test --parallel --no-daemon'
}
}
stage('Build Docker Image') {
steps {
sh "docker image build -t ${params.IMAGE_NAME} ."
}
}
stage('Remove Docker Image') {
when {
not {
anyOf {
branch 'main';
branch 'be-dev'
}
}
}
steps {
sh "docker images ${params.IMAGE_NAME} -q | xargs docker rmi -f"
}
}
stage('Tagging Docker Image') {
when {
anyOf {
branch 'main';
branch 'be-dev'
}
}
steps {
sh "docker image tag ${params.IMAGE_NAME} ${params.IMAGE_REGISTRY_ACCOUNT}/${params.IMAGE_NAME}:latest"
sh "docker image tag ${params.IMAGE_NAME} ${params.IMAGE_REGISTRY_ACCOUNT}/${params.IMAGE_NAME}:${BUILD_NUMBER}"
}
}
stage('Publish Docker Image') {
when {
anyOf {
branch 'main';
branch 'be-dev'
}
}
steps {
withDockerRegistry(credentialsId: 'docker-hub', url: 'https://index.docker.io/v1/') {
sh "docker image push --all-tags ${params.IMAGE_REGISTRY_ACCOUNT}/${params.IMAGE_NAME}"
sh "docker images ${params.IMAGE_NAME} -q | xargs docker rmi -f"
}
}
}
stage('Update Kubernetes manifests') {
when {
anyOf {
branch 'main';
branch 'be-dev'
}
}
steps {
git branch: 'main', credentialsId: 'cicd-sssdev', url: 'https://github.com/sss-develops/application-manifests.git'
sh "./change-image-tag.sh ${params.IMAGE_REGISTRY_ACCOUNT} ${params.IMAGE_NAME} ${env.BUILD_NUMBER} ${env.WORKSPACE}"
withCredentials([gitUsernamePassword(credentialsId: 'cicd-sssdev', gitToolName: 'Default')]) {
sh "git push origin main"
}
}
}
}
}