forked from agat-prog/mca-filesmanagement-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
82 lines (81 loc) · 3.29 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
def String pomVersion = ''
pipeline {
environment {
NAMESPACE = "${env.BRANCH_NAME == "main" ? "tfm-prod-agat-prog" : "tfm-pre-agat-prog"}"
MYSQL_HOST = "${env.BRANCH_NAME == "main" ? "mysql-service.tfm-prod-svc-agat-prog.svc.cluster.local" : "mysql-service.tfm-pre-svc-agat-prog.svc.cluster.local"}"
ZOOKEEPER_HOST = "${env.BRANCH_NAME == "main" ? "zookeeper.tfm-prod-svc-agat-prog.svc.cluster.local" : "zookeeper.tfm-pre-svc-agat-prog.svc.cluster.local"}"
DEPLOY = "${env.BRANCH_NAME == "main" || env.BRANCH_NAME == "develop" ? "true" : "false"}"
BUILD = "${env.BRANCH_NAME == "develop" || env.BRANCH_NAME.startsWith("release") || env.BRANCH_NAME == "main" ? "true" : "false"}"
REGISTRY = 'agatalba/tfm-mca-filemanagement-docs'
}
options {
buildDiscarder(logRotator(numToKeepStr: "2"))
disableConcurrentBuilds()
}
agent any
tools {
maven 'maven-3_8_6'
}
stages {
stage('Unit Test') {
steps {
script {
pomVersion = sh script: 'mvn help:evaluate -Dexpression=project.version -q -DforceStdout', returnStdout: true
}
echo "env.BRANCH_NAME -- ${env.BRANCH_NAME}"
echo "BUILD -- ${BUILD}"
echo "DEPLOY -- ${DEPLOY}"
echo "version -- ${pomVersion}"
sh "mvn clean test"
}
}
stage('Checkstyle') {
steps {
sh "mvn checkstyle:check"
}
}
stage('Deploy dependencies') {
steps {
configFileProvider(
[configFile(fileId: 'docs-maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn -s $MAVEN_SETTINGS deploy -DskipTests'
}
}
}
stage('PMD') {
steps {
sh "mvn pmd:check"
}
}
stage('Coverage check') {
steps {
sh "mvn verify"
}
}
stage('Build image') {
when {
environment name: 'BUILD', value: 'true'
}
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub-user', passwordVariable: 'pass', usernameVariable: 'user')]) {
echo "version -- ${REGISTRY}"
sh "mvn -f docs-api/pom.xml compile com.google.cloud.tools:jib-maven-plugin:3.2.0:build -Dimage=${REGISTRY}:${pomVersion} -DskipTests -Djib.to.auth.username=${user} -Djib.to.auth.password=${pass}"
}
}
}
stage('Deploy into Kubernetes') {
when {
environment name: 'DEPLOY', value: 'true'
}
agent {
docker {
image 'dtzar/helm-kubectl'
args '-u root -v /home/agat/.kube:/root/.kube'
}
}
steps {
sh "helm upgrade -n ${NAMESPACE} -f helm/values.yaml --set namespace=${NAMESPACE} --set image.tag='${pomVersion}' --set mysql.host=${MYSQL_HOST} --set zookeeper.host=${ZOOKEEPER_HOST} docs-release helm/"
}
}
}
}