-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
165 lines (165 loc) · 6.77 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
158
159
160
161
162
163
164
165
pipeline {
environment {
PROJECT_NAME = 'serrano-rot-pipeline'
DEPLOY = "${env.GIT_BRANCH == "origin/main" || env.GIT_BRANCH == "origin/develop" ? "true" : "false"}"
DEPLOY_UVT = "${env.GIT_BRANCH == "origin/main" ? "true" : "false"}"
ENGINE = "${env.GIT_BRANCH == "origin/main" ? "serrano-rot-engine" : "serrano-rot-engine-staging"}"
CONTROLLER = "${env.GIT_BRANCH == "origin/main" ? "serrano-rot-controller" : "serrano-rot-controller-staging"}"
VERSION = '0.1'
DOMAIN = 'localhost'
REGISTRY = 'serrano-harbor.rid-intrasoft.eu/serrano/serrano-rot-pipeline'
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')
PORT = "10020"
}
agent {
kubernetes {
cloud 'kubernetes'
defaultContainer 'jnlp'
yamlFile 'build.yaml'
}
}
stages {
stage('Install requirements') {
steps {
container('python') {
sh '/usr/local/bin/python -m pip install --upgrade pip'
sh 'pip3 install -r requirements.txt'
sh 'pip3 install --no-input cyclonedx-bom'
}
}
}
stage('Unit tests') {
steps {
container('python') {
sh 'python -m unittest serrano_rot.tests'
}
}
}
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: '39acd708-1e14-405e-932e-0af81c96554f', 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 Rot Engine in INTRA Kubernetes') {
when {
environment name: 'DEPLOY', value: 'true'
}
steps {
container('helm') {
sh "helm upgrade --install --force --wait --timeout 600s --namespace integration --set name=${ENGINE} --set image.tag=${VERSION} --set domain=${DOMAIN} ${ENGINE} ./helm/engine"
}
}
}
stage('Deploy Rot Controller in INTRA Kubernetes') {
when {
environment name: 'DEPLOY', value: 'true'
}
steps {
container('helm') {
sh "helm upgrade --install --force --wait --timeout 600s --namespace integration --set name=${CONTROLLER} --set image.tag=${VERSION} --set domain=${DOMAIN} ${CONTROLLER} ./helm/controller"
}
}
}
stage('Integration Tests') {
when {
environment name: 'DEPLOY', value: 'true'
}
steps {
container('python') {
sh "python -u /home/jenkins/agent/workspace/serrano-rot-pipeline/unittest/unit_test.py"
}
}
}
stage('Cleanup INTRA Deployment') {
when {
environment name: 'DEPLOY', value: 'true'
}
steps {
container('helm') {
sh "helm uninstall ${ENGINE} --namespace integration"
sh "helm uninstall ${CONTROLLER} --namespace integration"
sh "rm -rf deployments"
}
}
}
stage('Deploy ROT Engine in UVT Kubernetes') {
when {
environment name: 'DEPLOY_UVT', value: 'true'
}
steps {
container('helm') {
sh "echo Done"
sh "sleep 8"
/*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 "helm upgrade --install --force --wait --timeout 600s --kube-context=kubernetes-uvt --namespace integration --set name=${ENGINE} --set image.tag=${VERSION} --set domain=${DOMAIN} ${ENGINE} ./helm-uvt/engine"*/
}
}
}
stage('Deploy ROT Controller in UVT Kubernetes') {
when {
environment name: 'DEPLOY_UVT', value: 'true'
}
steps {
container('helm') {
sh "echo Done"
sh "sleep 8"
/*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 "helm upgrade --install --force --wait --timeout 600s --kube-context=kubernetes-uvt --namespace integration --set name=${CONTROLLER} --set image.tag=${VERSION} --set domain=${DOMAIN} ${CONTROLLER} ./helm-uvt/controller"*/
}
}
}
}
}