forked from sockshop-openshift/k8s-deploy-staging
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
95 lines (92 loc) · 4 KB
/
Jenkinsfile
File metadata and controls
95 lines (92 loc) · 4 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
@Library('dynatrace@master') _
pipeline {
parameters {
string(name: 'APP_NAME', defaultValue: '', description: 'The name of the service to deploy.', trim: true)
string(name: 'TAG_STAGING', defaultValue: '', description: 'The image of the service to deploy.', trim: true)
string(name: 'VERSION', defaultValue: '', description: 'The version of the service to deploy.', trim: true)
}
agent {
label 'kubegit'
}
stages {
stage('Update Deployment and Service specification') {
steps {
container('git') {
withCredentials([usernamePassword(credentialsId: 'git-credentials-acm', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh "git config --global user.email ${env.GITHUB_USER_EMAIL}"
sh "git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${env.GITHUB_ORGANIZATION}/k8s-deploy-staging"
sh "cd k8s-deploy-staging/ && sed -i 's#image: .*#image: ${env.TAG_STAGING}#' ${env.APP_NAME}.yml"
sh "cd k8s-deploy-staging/ && git add ${env.APP_NAME}.yml && git commit -m 'Update ${env.APP_NAME} version ${env.VERSION}'"
sh "cd k8s-deploy-staging/ && git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${env.GITHUB_ORGANIZATION}/k8s-deploy-staging"
}
}
}
}
stage('Deploy to staging namespace') {
steps {
checkout scm
container('kubectl') {
sh "kubectl -n staging apply -f ${env.APP_NAME}.yml"
}
}
}
/*
stage('DT Deploy Event') {
steps {
container("curl") {
// send custom deployment event to Dynatrace
sh "curl -X POST \"$DT_TENANT_URL/api/v1/events?Api-Token=$DT_API_TOKEN\" -H \"accept: application/json\" -H \"Content-Type: application/json\" -d \"{ \\\"eventType\\\": \\\"CUSTOM_DEPLOYMENT\\\", \\\"attachRules\\\": { \\\"tagRule\\\" : [{ \\\"meTypes\\\" : [\\\"SERVICE\\\"], \\\"tags\\\" : [ { \\\"context\\\" : \\\"CONTEXTLESS\\\", \\\"key\\\" : \\\"app\\\", \\\"value\\\" : \\\"${env.APP_NAME}\\\" }, { \\\"context\\\" : \\\"CONTEXTLESS\\\", \\\"key\\\" : \\\"environment\\\", \\\"value\\\" : \\\"staging\\\" } ] }] }, \\\"deploymentName\\\":\\\"${env.JOB_NAME}\\\", \\\"deploymentVersion\\\":\\\"${env.VERSION}\\\", \\\"deploymentProject\\\":\\\"\\\", \\\"ciBackLink\\\":\\\"${env.BUILD_URL}\\\", \\\"source\\\":\\\"Jenkins\\\", \\\"customProperties\\\": { \\\"Jenkins Build Number\\\": \\\"${env.BUILD_ID}\\\", \\\"Git commit\\\": \\\"${env.GIT_COMMIT}\\\" } }\" "
}
}
}
*/
stage('Run production ready e2e check in staging') {
steps {
echo "Waiting for the service to start..."
sleep 150
recordDynatraceSession(
envId: 'Dynatrace Tenant',
testCase: 'loadtest',
tagMatchRules: [
[
meTypes: [
[meType: 'SERVICE']
],
tags: [
[context: 'CONTEXTLESS', key: 'app', value: "${env.APP_NAME}"],
[context: 'CONTEXTLESS', key: 'environment', value: 'staging']
]
]
]
)
{
container('jmeter') {
script {
def status = executeJMeter (
scriptName: "jmeter/front-end_e2e_load.jmx",
resultsDir: "e2eCheck_${env.APP_NAME}",
serverUrl: "front-end.staging",
serverPort: 8080,
checkPath: '/health',
vuCount: 10,
loopCount: 5,
LTN: "e2eCheck_${BUILD_NUMBER}",
funcValidation: false,
avgRtValidation: 4000
)
if (status != 0) {
currentBuild.result = 'FAILED'
error "Production ready e2e check in staging failed."
}
}
}
}
perfSigDynatraceReports(
envId: 'Dynatrace Tenant',
nonFunctionalFailure: 1,
specFile: "monspec/e2e_perfsig.json"
)
}
}
}
}