-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
157 lines (154 loc) · 8.14 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
pipeline {
environment {
PROJECT_NAME = 'service-assurance-ede'
DEPLOY = "${env.GIT_BRANCH == "origin/master" || env.GIT_BRANCH == "origin/develop" ? "true" : "false"}"
DEPLOY_UVT = "${env.GIT_BRANCH == "origin/master" ? "true" : "false"}"
CHART_NAME = "${env.GIT_BRANCH == "origin/master" ? "service-assurance-ede" : "service-assurance-ede-staging"}"
VERSION = '0.0.23'
DOMAIN = 'localhost'
REGISTRY = 'serrano-harbor.rid-intrasoft.eu/serrano/service-assurance-ede'
REGISTRY_URL = 'https://serrano-harbor.rid-intrasoft.eu/serrano'
REGISTRY_CREDENTIAL = 'harbor-jenkins'
UVT_KUBERNETES_PUBLIC_ADDRESS = 'api.k8s.cloud.ict-serrano.eu'
INTEGRATION_OPERATOR_TOKEN = credentials('uvt-integration-operator-token')
UVT_K8S_CA = 'LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUMvakNDQWVhZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeU1EY3lOVEUyTURZd09Wb1hEVE15TURjeU1qRTJNRFl3T1Zvd0ZURVRNQkVHQTFVRQpBeE1LYT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DMvUmZPeWhCMCtwYm9Fb1pQNHhGL0t1MW9CcktobDF4MFgvTHB5UGNzcE9lMzE5eCttUm1CCklDSnBSRk10ZkVaQW1nN2R5SWN2Q3EwSEhJajk5TUR1Mm0zTWJDRmx4QUx6WjRuZWJaVDdEbTlFc2x6T29NaUMKNUxNPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg=='
}
agent {
kubernetes {
cloud 'kubernetes'
defaultContainer 'jnlp'
yamlFile 'build.yaml'
}
}
stages {
stage('Install requirements') {
steps {
container('python') {
sh '/usr/bin/apt -y update && /usr/bin/apt -y install gcc && /usr/bin/apt clean'
sh '/usr/local/bin/python -m pip install --upgrade pip'
sh 'pip install --no-cache-dir -r requirements_service.txt'
sh 'pip install --no-input cyclonedx-bom'
}
}
}
stage('Sonarqube') {
environment {
scannerHome = tool 'SonarQubeScanner'
}
steps {
container('java') {
withSonarQubeEnv('sonarqube') {
sh "${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=${PROJECT_NAME}"
}
timeout(time: 10, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
}
stage('Generate BOM') {
steps {
container('python') {
sh 'cyclonedx-bom -e -F -o ./bom.xml'
}
}
}
stage('Dependency Track') {
steps {
container('python') {
dependencyTrackPublisher artifact: 'bom.xml', projectId: '7727e147-419b-4283-af49-c1ef40e5e712', synchronous: true
}
}
}
stage('Docker Build') {
when {
environment name: 'DEPLOY', value: 'true'
}
steps {
container('docker') {
sh "docker build -t ${REGISTRY}:${VERSION} ."
}
}
}
stage('Docker Publish') {
when {
environment name: 'DEPLOY', value: 'true'
}
steps {
container('docker') {
withDockerRegistry([credentialsId: "${REGISTRY_CREDENTIAL}", url: "${REGISTRY_URL}"]) {
sh "docker push ${REGISTRY}:${VERSION}"
}
}
}
}
stage('Deploy Service-Assurance-EDE in INTRA Kubernetes') {
when {
environment name: 'DEPLOY', value: 'true'
}
steps {
container('helm') {
//sh "helm uninstall --wait --timeout 600s --namespace integration ${CHART_NAME}-integration"
sh "helm upgrade --install --force --wait --timeout 600s --namespace integration --set service.port=5551 --set image.tag=${VERSION} ${CHART_NAME}-integration ./helm"
}
}
}
stage('Integration Tests') {
when {
environment name: 'DEPLOY', value: 'true'
}
steps {
container('java') {
script {
echo 'Run your Integration Tests here'
//sleep 20 // Sleep is not required if the readiness probe is enabled
try {
String testName = "1. Check that app is running - 200 response code"
String url = "http://${CHART_NAME}-integration.integration:5551/ping"
String responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true)
if (responseCode != '200') {
error("$testName: Returned status code = $responseCode when calling $url")
}
testName = '2. Validate greeting response without request parameters'
url = "http://${CHART_NAME}-integration.integration:5551/ping"
String responseBody = sh(label: testName, script: "curl -m 10 -sL $url | tr -d [:space:]", returnStdout: true)
if (responseBody != '{"message":"Iamalive","ok":true}') {
error("$testName: Unexpected response body = $responseBody when calling $url")
}
} catch (ignored) {
currentBuild.result = 'FAILURE'
echo "Integration Tests failed"
echo "$ignored"
sh "exit 1"
}
}
}
}
}
stage('Cleanup Deployment') {
when {
environment name: 'DEPLOY', value: 'true'
}
steps {
container('helm') {
sh "helm uninstall ${CHART_NAME}-integration --namespace integration"
}
}
}
stage('Deploy in UVT Kubernetes') {
when {
environment name: 'DEPLOY_UVT', value: 'true'
}
steps {
container('helm') {
sh "echo -n $UVT_K8S_CA | base64 -d > uvt.cer"
sh "kubectl config set-cluster kubernetes-uvt --certificate-authority=uvt.cer --embed-certs=true --server=https://${UVT_KUBERNETES_PUBLIC_ADDRESS}:6443"
sh "kubectl config set-credentials integration-operator --token=${INTEGRATION_OPERATOR_TOKEN}"
sh "kubectl config set-context kubernetes-uvt --cluster=kubernetes-uvt --user=integration-operator"
sh 'sed -i "s/__docker__image__tag__/${VERSION}/" ./helm/values-uvt-serrano.yaml'
sh "helm upgrade --install --wait --timeout 600s --kube-context=kubernetes-uvt --namespace integration ${CHART_NAME} -f ./helm/values-uvt-serrano.yaml ./helm"
}
}
}
}
}