Jenkinsfile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. def BUILD_AUTH_SERVICE = false
  2. def BUILD_CONFIG = false
  3. def BUILD_FRONTEND_CLIENT = false
  4. def BUILD_GATEWAY = false
  5. def BUILD_PRODUCT_SERVICE = false
  6. def BUILD_REGISTRY = false
  7. def BUILD_REVIEW_SERVICE = false
  8. pipeline {
  9. agent any
  10. tools {
  11. maven 'maven-3.6.3'
  12. jdk 'openjdk-8'
  13. }
  14. environment {
  15. DOCKER_CREDENTIALS = credentials('paragon-docker-zyx42')
  16. }
  17. stages {
  18. stage('Validation') {
  19. steps {
  20. dir('auth-service') {
  21. script {
  22. // Using the git command to check the difference between previous successful commit.
  23. // ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} is an environment variable comes with GIT Jenkins plugin
  24. // There is a drawback though, if it is the first time you are running this job, this variable is not available and fails the build
  25. // For the first time you have to use ${env.GIT_COMMIT} itself at both places to pass the build. A hack but worth it for future builds.
  26. if (env.GIT_COMMIT != null) {
  27. strCount = sh(returnStdout: true, script: "git diff --name-only ${env.GIT_COMMIT} ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} | grep auth-service | wc -l").trim()
  28. if (strCount == "0") {
  29. echo "Skipping build of auth-service, no files updated"
  30. } else {
  31. echo "Changes found in the auth-service"
  32. BUILD_AUTH_SERVICE = true
  33. }
  34. } else {
  35. echo "Apparently you're running this job for the first time, thus env.GIT_COMMIT is not available and validation will be skipped"
  36. BUILD_AUTH_SERVICE = true
  37. }
  38. }
  39. }
  40. dir('config') {
  41. script {
  42. if (env.GIT_COMMIT != null) {
  43. strCount = sh(returnStdout: true, script: "git diff --name-only ${env.GIT_COMMIT} ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} | grep config | wc -l").trim()
  44. if (strCount == "0") {
  45. echo "Skipping build of config, no files updated"
  46. } else {
  47. echo "Changes found in the config"
  48. BUILD_CONFIG = true
  49. }
  50. } else {
  51. echo "Apparently first run, thus env.GIT_COMMIT is not available and validation will be skipped"
  52. BUILD_CONFIG = true
  53. }
  54. }
  55. }
  56. dir('frontend-client') {
  57. script {
  58. if (env.GIT_COMMIT != null) {
  59. strCount = sh(returnStdout: true, script: "git diff --name-only ${env.GIT_COMMIT} ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} | grep frontend-client | wc -l").trim()
  60. if (strCount == "0") {
  61. echo "Skipping build of frontend-client, no files updated"
  62. } else {
  63. echo "Changes found in the frontend-client"
  64. BUILD_FRONTEND_CLIENT = true
  65. }
  66. } else {
  67. echo "Apparently first run, thus env.GIT_COMMIT is not available and validation will be skipped"
  68. BUILD_FRONTEND_CLIENT = true
  69. }
  70. }
  71. }
  72. dir('gateway') {
  73. script {
  74. if (env.GIT_COMMIT != null) {
  75. strCount = sh(returnStdout: true, script: "git diff --name-only ${env.GIT_COMMIT} ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} | grep gateway | wc -l").trim()
  76. if (strCount == "0") {
  77. echo "Skipping build of gateway, no files updated"
  78. } else {
  79. echo "Changes found in the gateway"
  80. BUILD_GATEWAY = true
  81. }
  82. } else {
  83. echo "Apparently first run, thus env.GIT_COMMIT is not available and validation will be skipped"
  84. BUILD_GATEWAY = true
  85. }
  86. }
  87. }
  88. dir('product-service') {
  89. script {
  90. if (env.GIT_COMMIT != null) {
  91. strCount = sh(returnStdout: true, script: "git diff --name-only ${env.GIT_COMMIT} ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} | grep product-service | wc -l").trim()
  92. if (strCount == "0") {
  93. echo "Skipping build of product-service, no files updated"
  94. } else {
  95. echo "Changes found in the product-service"
  96. BUILD_PRODUCT_SERVICE = true
  97. }
  98. } else {
  99. echo "Apparently first run, thus env.GIT_COMMIT is not available and validation will be skipped"
  100. BUILD_PRODUCT_SERVICE = true
  101. }
  102. }
  103. }
  104. dir('registry') {
  105. script {
  106. if (env.GIT_COMMIT != null) {
  107. strCount = sh(returnStdout: true, script: "git diff --name-only ${env.GIT_COMMIT} ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} | grep registry | wc -l").trim()
  108. if (strCount == "0") {
  109. echo "Skipping build of registry, no files updated"
  110. } else {
  111. echo "Changes found in the registry"
  112. BUILD_REGISTRY = true
  113. }
  114. } else {
  115. echo "Apparently first run, thus env.GIT_COMMIT is not available and validation will be skipped"
  116. BUILD_REGISTRY = true
  117. }
  118. }
  119. }
  120. dir('review-service') {
  121. script {
  122. if (env.GIT_COMMIT != null) {
  123. strCount = sh(returnStdout: true, script: "git diff --name-only ${env.GIT_COMMIT} ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} | grep review-service | wc -l").trim()
  124. if (strCount == "0") {
  125. echo "Skipping build of review-service, no files updated"
  126. } else {
  127. echo "Changes found in the review-service"
  128. BUILD_REVIEW_SERVICE = true
  129. }
  130. } else {
  131. echo "Apparently first run, thus env.GIT_COMMIT is not available and validation will be skipped"
  132. BUILD_REVIEW_SERVICE = true
  133. }
  134. }
  135. }
  136. }
  137. }
  138. stage('auth-service') {
  139. when {
  140. expression {
  141. BUILD_AUTH_SERVICE
  142. }
  143. }
  144. stages {
  145. stage('Build') {
  146. steps {
  147. dir('auth-service') {
  148. sh "mvn clean package -DskipTests"
  149. }
  150. }
  151. }
  152. stage('Make container') {
  153. steps {
  154. dir('auth-service') {
  155. sh "docker build -t zyx42/paragon-auth-service:latest ."
  156. }
  157. }
  158. }
  159. }
  160. post {
  161. success {
  162. sh 'docker login -u "\"$DOCKER_CREDENTIALS_USR\"" -p "\"$DOCKER_CREDENTIALS_PSW\""'
  163. sh "docker push zyx42/paragon-auth-service:latest"
  164. }
  165. }
  166. }
  167. stage('config') {
  168. when {
  169. expression {
  170. BUILD_CONFIG
  171. }
  172. }
  173. stages {
  174. stage('Build') {
  175. steps {
  176. dir('config') {
  177. sh "mvn clean package -DskipTests"
  178. }
  179. }
  180. }
  181. stage('Make container') {
  182. steps {
  183. dir('config') {
  184. sh "docker build -t zyx42/paragon-config:latest ."
  185. }
  186. }
  187. }
  188. }
  189. post {
  190. success {
  191. sh 'docker login -u "\"$DOCKER_CREDENTIALS_USR\"" -p "\"$DOCKER_CREDENTIALS_PSW\""'
  192. sh "docker push zyx42/paragon-config:latest"
  193. }
  194. }
  195. }
  196. stage('frontend-client') {
  197. when {
  198. expression {
  199. BUILD_FRONTEND_CLIENT
  200. }
  201. }
  202. stages {
  203. stage('Build') {
  204. steps {
  205. dir('frontend-client') {
  206. sh "npm install"
  207. sh "ng build --prod"
  208. }
  209. }
  210. }
  211. stage('Make container') {
  212. steps {
  213. dir('frontend-client') {
  214. sh "docker build -t zyx42/paragon-frontend-client:latest ."
  215. }
  216. }
  217. }
  218. }
  219. post {
  220. success {
  221. sh 'docker login -u "\"$DOCKER_CREDENTIALS_USR\"" -p "\"$DOCKER_CREDENTIALS_PSW\""'
  222. sh "docker push zyx42/paragon-frontend-client:latest"
  223. }
  224. }
  225. }
  226. stage('gateway') {
  227. when {
  228. expression {
  229. BUILD_GATEWAY
  230. }
  231. }
  232. stages {
  233. stage('Build') {
  234. steps {
  235. dir('gateway') {
  236. sh "mvn clean package -DskipTests"
  237. }
  238. }
  239. }
  240. stage('Make container') {
  241. steps {
  242. dir('gateway') {
  243. sh "docker build -t zyx42/paragon-gateway:latest ."
  244. }
  245. }
  246. }
  247. }
  248. post {
  249. success {
  250. sh 'docker login -u "\"$DOCKER_CREDENTIALS_USR\"" -p "\"$DOCKER_CREDENTIALS_PSW\""'
  251. sh "docker push zyx42/paragon-gateway:latest"
  252. }
  253. }
  254. }
  255. stage('product-service') {
  256. when {
  257. expression {
  258. BUILD_PRODUCT_SERVICE
  259. }
  260. }
  261. stages {
  262. stage('Build') {
  263. steps {
  264. dir('product-service') {
  265. sh "mvn clean package -DskipTests"
  266. }
  267. }
  268. }
  269. stage('Make container') {
  270. steps {
  271. dir('product-service') {
  272. sh "docker build -t zyx42/paragon-product-service:latest ."
  273. }
  274. }
  275. }
  276. }
  277. post {
  278. success {
  279. sh 'docker login -u "\"$DOCKER_CREDENTIALS_USR\"" -p "\"$DOCKER_CREDENTIALS_PSW\""'
  280. sh "docker push zyx42/paragon-product-service:latest"
  281. }
  282. }
  283. }
  284. stage('registry') {
  285. when {
  286. expression {
  287. BUILD_REGISTRY
  288. }
  289. }
  290. stages {
  291. stage('Build') {
  292. steps {
  293. dir('registry') {
  294. sh "mvn clean package -DskipTests"
  295. }
  296. }
  297. }
  298. stage('Make container') {
  299. steps {
  300. dir('registry') {
  301. sh "docker build -t zyx42/paragon-registry:latest ."
  302. }
  303. }
  304. }
  305. }
  306. post {
  307. success {
  308. sh 'docker login -u "\"$DOCKER_CREDENTIALS_USR\"" -p "\"$DOCKER_CREDENTIALS_PSW\""'
  309. sh "docker push zyx42/paragon-registry:latest"
  310. }
  311. }
  312. }
  313. stage('review-service') {
  314. when {
  315. expression {
  316. BUILD_REVIEW_SERVICE
  317. }
  318. }
  319. stages {
  320. stage('Build') {
  321. steps {
  322. dir('review-service') {
  323. sh "mvn clean package -DskipTests"
  324. }
  325. }
  326. }
  327. stage('Make container') {
  328. steps {
  329. dir('review-service') {
  330. sh "docker build -t zyx42/paragon-review-service:latest ."
  331. }
  332. }
  333. }
  334. }
  335. post {
  336. success {
  337. sh 'docker login -u "\"$DOCKER_CREDENTIALS_USR\"" -p "\"$DOCKER_CREDENTIALS_PSW\""'
  338. sh "docker push zyx42/paragon-review-service:latest"
  339. }
  340. }
  341. }
  342. }
  343. }