-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Jenkinsfile
128 lines (117 loc) · 4.62 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
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
128
pipeline {
agent none
environment {
NX_BRANCH = env.BRANCH_NAME.replace('PR-', '')
}
stages {
stage('Pipeline') {
parallel {
stage('Main') {
when {
branch 'main'
}
agent any
steps {
sh "pnpm install"
sh "npx nx-cloud start-ci-run --stop-agents-after='build'"
sh "npx nx format:check"
sh "npx nx affected --base=HEAD~1 -t lint --parallel=3 & npx nx affected --base=HEAD~1 -t test --parallel=3 --configuration=ci & npx nx affected --base=HEAD~1 -t build --parallel=3"
}
}
stage('PR') {
when {
not { branch 'main' }
}
agent any
steps {
sh "pnpm install"
sh "npx nx-cloud start-ci-run --stop-agents-after='build'"
sh "npx nx format:check"
sh "npx nx affected --base origin/${env.CHANGE_TARGET} -t lint --parallel=2 & npx nx affected --base origin/${env.CHANGE_TARGET} -t test --parallel=2 --configuration=ci & npx nx affected --base origin/${env.CHANGE_TARGET} -t build --parallel=2"
}
}
stages {
stage('Agent1') {
agent any
steps {
sh "pnpm install"
sh "npx nx-cloud start-agent"
}
}
stage('Agent2') {
agent any
steps {
sh "pnpm install"
sh "npx nx-cloud start-agent"
}
}
stage('Agent3') {
agent any
steps {
sh "pnpm install"
sh "npx nx-cloud start-agent"
}
}
}
}
}
}
stages {
stage("build & SonarQube analysis") {
environment {
SCANNER_HOME = tool 'SonarQubeScanner'
}
steps {
withSonarQubeEnv('SonarQube') {
sh "${SCANNER_HOME}/bin/sonar-scanner"
}
}
}
}
stages {
stage('Build Docker Images') {
when {
branch 'main'
}
agent any
steps {
sh "docker build -f apps/api/api-gateway/Dockerfile ${env.DOCKER_REGISTRY}/${env.DOCKER_USERNAME}/api-gateway:latest"
sh "docker build -f apps/api/auth-svc/Dockerfile ${env.DOCKER_REGISTRY}/${env.DOCKER_USERNAME}/auth-svc:latest"
sh "docker build -f apps/api/law-svc/Dockerfile ${env.DOCKER_REGISTRY}/${env.DOCKER_USERNAME}/law-svc:latest"
sh "docker build -f apps/api/search-svc/Dockerfile ${env.DOCKER_REGISTRY}/${env.DOCKER_USERNAME}/search-svc:latest"
sh "docker build -f apps/api/website/Dockerfile ${env.DOCKER_REGISTRY}/${env.DOCKER_USERNAME}/website:latest"
}
}
stages('Login to Github container registry') {
when {
branch 'main'
}
agent any
steps {
withCredentials([usernamePassword(credentialsId: 'GITHUB_CREDENTIALS', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
sh "docker login ghcr.io -u ${env.USERNAME} -p ${env.PASSWORD}"
}
}
}
stages('Push Docker Images') {
when {
branch 'main'
}
agent any
steps {
sh "docker push ${env.DOCKER_REGISTRY}/${env.DOCKER_USERNAME}/api-gateway:latest"
sh "docker push ${env.DOCKER_REGISTRY}/${env.DOCKER_USERNAME}/auth-svc:latest"
sh "docker push ${env.DOCKER_REGISTRY}/${env.DOCKER_USERNAME}/law-svc:latest"
sh "docker push ${env.DOCKER_REGISTRY}/${env.DOCKER_USERNAME}/search-svc:latest"
sh "docker push ${env.DOCKER_REGISTRY}/${env.DOCKER_USERNAME}/website:latest"
}
}
}
post {
failure {
mail to: '[email protected]',
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
body: "Something is wrong with ${env.BUILD_URL}"
}
}
}