-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathJenkinsfile
More file actions
293 lines (284 loc) · 9.6 KB
/
Jenkinsfile
File metadata and controls
293 lines (284 loc) · 9.6 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
def configuration = [vaultUrl: "${VAULT_URL}", vaultCredentialId: "vault-app-role", engineVersion: 2]
def secrets = [
[path: 'secret/jenkins/cloudifyaws', engineVersion: 2, secretValues: [
[envVar: 'AWS_MANAGER_USERNAME', vaultKey: 'username'],
[envVar: 'AWS_MANAGER_TENANT', vaultKey: 'tenant'],
[envVar: 'AWS_MANAGER_IP', vaultKey: 'ip'],
[envVar: 'AWS_MANAGER_PASSWORD', vaultKey: 'password']]
],
[path: 'secret/jenkins/aws', engineVersion: 2, secretValues: [
[envVar: 'AWS_ACCESS_KEY_ID', vaultKey: 'aws_access_key_id'],
[envVar: 'AWS_SECRET_ACCESS_KEY', vaultKey: 'aws_secret_access_key']]
],
[path: 'secret/jenkins/cloudify', engineVersion: 2, secretValues: [
[envVar: 'LICENSE', vaultKey: 'license']]
],
[path: 'secret/jenkins/infracost', engineVersion: 2, secretValues: [
[envVar: 'INFRACOST_API_KEY', vaultKey: 'api_key']]
],
[path: 'secret/jenkins/catalog', engineVersion: 2, secretValues: [
[envVar: 'GH_TOKEN', vaultKey: 'gh_token']]
]
]
def terminateCloudifyManager(){
try {
sh """#!/bin/bash
source ${TEST_RESULT_DIR}/conn_details
cfy profile use -u \$AWS_MANAGER_USERNAME -p \$AWS_MANAGER_PASSWORD -t \$AWS_MANAGER_TENANT --ssl \$AWS_MANAGER_IP
export CLOUDIFY_SSL_TRUST_ALL=true
export PYTHONWARNINGS="ignore:Unverified HTTPS request"
cfy uninstall --allow-custom-parameters -p force=True ${env.BP_ID}
"""
} catch(Exception e){
echo 'Exception occurred: ' + e.toString()
continuePipeline = true
currentBuild.result = 'SUCCESS'
}
}
@Library('pipeline-shared-library') _
pipeline{
agent{
kubernetes{
defaultContainer 'cloudify'
yaml '''
spec:
volumes:
- name: dshm
emptyDir:
medium: Memory
- name: shared-data-volume
peristentVolumeClaim:
claimName: shared-data
containers:
- name: jnlp
image: jenkins/inbound-agent:4.11.2-2
resources:
limits:
cpu: 0.3
memory: 256Mi
- name: cloudify
image: 263721492972.dkr.ecr.eu-west-1.amazonaws.com/cloudify-python3.10
volumeMounts:
- mountPath: /tmp/data
name: shared-data-volume
command:
- cat
tty: true
resources:
requests:
cpu: 1.0
memory: 3Gi
limits:
memory: 3.5Gi
securityContext:
runAsUser: 0
privileged: true
nodeSelector:
instance-type: spot
'''
}
}
options {
checkoutToSubdirectory('cloudify-catalog')
buildDiscarder(logRotator(numToKeepStr:'10'))
timeout(time: 60, unit: 'MINUTES')
timestamps()
}
triggers {
cron(env.BRANCH_NAME == '6.4.0-build' ? '0 */12 * * *' : '')
}
parameters {
string(name: 'TEST_BLUEPRINT', defaultValue: '', description: 'Blueprint ID to test.')
choice(name: 'TEST_CASE', choices: "upload\ninstall\nsingle_upload\nsingle_install", description: 'Test case type, applicable only if TEST_BLUEPRINTS set to true, single_{option} takes into account the value from TEST_BLUEPRINT')
choice(name: 'BPS_SCOPE', choices: "changed\nall", description: 'Test all or only changed bps from Pull Request.')
}
environment {
PROJECT = 'cloudify-catalog'
WORKSPACE = "${env.WORKSPACE}"
BP_ID = "ec2-cloudify-catalog-blueprint-${env.GIT_BRANCH}-${env.BUILD_NUMBER}"
SUFFIX = "6.4.0-.dev1"
BPS_SCOPE = "${params.BPS_SCOPE}"
TEST_CASE = "${params.TEST_CASE}"
TEST_BLUEPRINT = "${params.TEST_BLUEPRINT}"
TEST_RESULT_DIR = "/tmp/data"
TEST_RESULT_PATH = "${env.TEST_RESULT_DIR}/junit_report.xml"
EC2_META_DATA = "http://169.254.169.254/latest/meta-data/"
}
stages{
stage('prepare'){
steps {
script{
container('cloudify'){
dir("${env.WORKSPACE}/${env.PROJECT}"){
common = load "common.groovy"
sh """
set -eux
pip install --upgrade pip
pip install -r requirements.txt
curl -sfL https://cloudify.co/get-lint | sh -
"""
}
}
}
}
}
stage('validate_catalog_yaml'){
steps{
container('cloudify'){
dir("${env.WORKSPACE}/${env.PROJECT}"){
sh """
python catalog_definition_linter.py
"""
}
}
}
}
stage('build'){
steps{
container('cloudify'){
dir("${env.WORKSPACE}/${env.PROJECT}"){
withVault([configuration: configuration, vaultSecrets: secrets]){
setupGithubSSHKey()
sh """
export TEST_RESULT_PATH=${env.TEST_RESULT_PATH}
export GH_TOKEN=${env.GH_TOKEN}
export BPS_SCOPE=${env.BPS_SCOPE}
python catalog.py
"""
}
}
}
}
}
stage('validate_built_catalogs'){
steps{
container('cloudify'){
dir("${env.WORKSPACE}/${env.PROJECT}"){
setupGithubSSHKey()
sh """
python catalog_linter.py
"""
}
}
}
}
stage('test'){
when {
anyOf {
expression {
container('cloudify'){
dir("${env.WORKSPACE}/${env.PROJECT}"){
withVault([configuration: configuration, vaultSecrets: secrets]){
common.checkChanges().trim() != '0'
}
}
}
}
expression { params.BPS_SCOPE == 'all' }
}
}
stages {
stage('run_cfy_lint_cm_tests'){
parallel{
stage('run_cfy_lint'){
steps{
container('cloudify'){
dir("${env.WORKSPACE}/${env.PROJECT}"){
withVault([configuration: configuration, vaultSecrets: secrets]){
script{
catchError(message: 'Failure on: Test cfy lint', buildResult: 'SUCCESS', stageResult:
'FAILURE') {
common.runCfyLinter()
}
}
}
}
}
}
}
stage('run_cm_tests'){
stages {
stage('deploy_cloudify_manager') {
steps {
script {
buildState = 'FAILURE'
catchError(message: 'Failure on: Deploy Cloudify Manager', buildResult: 'SUCCESS', stageResult:
'FAILURE') {
container('cloudify') {
setupGithubSSHKey()
dir("${env.WORKSPACE}/${env.PROJECT}") {
withVault([configuration: configuration, vaultSecrets: secrets]){
echo 'Create EC2 instance'
common.createEc2Instance()
echo 'Configure Cloudify Manager'
common.configureCloudifyManager()
}
}
}
// If we reach here that means all of the above passed
buildState = 'SUCCESS'
}
}
}
}
stage('test_blueprints'){
steps {
script {
buildState = 'FAILURE'
catchError(message: 'Failure on: Test blueprints', buildResult: 'SUCCESS', stageResult:
'FAILURE') {
container('cloudify') {
dir("${env.WORKSPACE}/${env.PROJECT}") {
withVault([configuration: configuration, vaultSecrets: secrets]){
echo 'Test blueprints'
sh """
set -x
export GH_TOKEN=${env.GH_TOKEN}
export BPS_SCOPE=${env.BPS_SCOPE}
"""
common.testBlueprints()
echo 'Export connection details'
common.exportManagerConnDetails()
}
}
// If we reach here that means all of the above passed
buildState = 'SUCCESS'
}
}
}
}
post {
always {
terminateCloudifyManager()
}
}
}
}
}
}
}
}
}
stage('upload_artifacts'){
steps{
withCredentials([
usernamePassword(
credentialsId: 'aws-cli',
usernameVariable: 'ID',
passwordVariable: 'SECRET'
)]) {
container('cloudify'){
dir("${env.WORKSPACE}/${env.PROJECT}"){
setupGithubSSHKey()
sh '''
export ID="$ID"
export SECRET="$SECRET"
python upload_artifacts.py
'''
}
}
}
}
}
}
}