-
Notifications
You must be signed in to change notification settings - Fork 32
/
Jenkinsfile_slafails
133 lines (130 loc) · 4.5 KB
/
Jenkinsfile_slafails
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
pipeline {
agent none
parameters {
string(defaultValue: "${NEOLOAD_CLI_NLW_TOKEN}", description: 'Neoload Web Token', name: 'token')
string(defaultValue: "${NEOLOAD_CLI_ZONE_STATIC}", description: 'Zone identifier', name: 'zone_id')
string(defaultValue: "${NEOLOAD_CLI_NLW_URL}", description: 'NeoLoad Web Api Url', name: 'api_url')
}
environment {
CLI_BRANCH="master"
MAX_SLA_FAILURE_PERCENT=25 // if more than x% of the time a per-run interval failed, stop test immediately
}
stages {
stage ('Prep workspace') {
agent any
steps {
cleanWs()
script {
try { sh "docker rmi \$(docker images -a --filter=\"label=${env.CLI_BRANCH}\" --format=\"{{.ID}}\") --force" }
catch(error) {}
}
// write a custom Docker image for python + CLI with socket permissions
writeFile file: "Dockerfile", text: """
FROM python:3.7-alpine
# add the Jenkins user to container for file permissions and Docker socket chmod
RUN apk add -q git shadow sudo
RUN addgroup -g 993 -S jenkins && adduser --uid 997 -S jenkins -G jenkins && passwd -d jenkins
RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/jenkins && chmod 0440 /etc/sudoers.d/jenkins
# pre-install NeoLoad CLI
WORKDIR /opt/neoload
RUN git clone --single-branch --branch """+env.CLI_BRANCH+""" https://github.com/Neotys-Labs/neoload-cli.git
RUN cd neoload-cli && python3 -m pip install -q .
USER jenkins
"""
}
}
stage('Attach Worker') {
agent {
dockerfile {
additionalBuildArgs "--rm --label \"${env.CLI_BRANCH}\""
args "-v /var/run/docker.sock:/var/run/docker.sock"
}
}
stages {
stage('Prepare docker') {
steps {
sh 'sudo chmod 666 /var/run/docker.sock'
sh 'neoload --version'
}
}
stage('Get NeoLoad Project') {
steps {
withEnv(["HOME=${env.WORKSPACE}"]) {
git url: 'https://github.com/Neotys-Labs/neoload-cli.git',
branch: env.CLI_BRANCH
}
}
}
stage('Prepare Neoload test') {
steps {
withEnv(["HOME=${env.WORKSPACE}"]) {
sh """neoload \
login --url ${params.api_url} ${params.token} \
test-settings --zone ${params.zone_id} --lgs 2 --scenario fullTest createorpatch "example-Jenkins-SLAfail" \
project --path tests/neoload_projects/example_1/ upload
"""
//sh 'neoload docker attach' // starts additional containers for load infrastructure on Docker host
}
}
}
stage('Run Test') {
stages {
stage('Kick off test async') {
steps {
withEnv(["HOME=${env.WORKSPACE}"]) {
sh """neoload run \
--detached \
--name "Jenkins pipeline performance regression test ${BUILD_NUMBER}" \
--external-url '${BUILD_URL}' \
--external-url-label 'Jenkins build ${BUILD_NUMBER}' \
--description "Jenkins result description" \
--web-vu 25 \
--as-code default.yaml,slas/uat.yaml
"""
}
}
}
stage('Monitor test') {
parallel {
stage('Monitor SLAs') {
steps {
withEnv(["HOME=${env.WORKSPACE}"]) {
sh "neoload fastfail --max-failure ${env.MAX_SLA_FAILURE_PERCENT} slas cur"
}
}
}
stage('Wait for test finale') {
steps {
withEnv(["HOME=${env.WORKSPACE}"]) {
sh 'neoload wait cur'
}
}
}
} //end parallel
}
} // end stages
post {
always {
withEnv(["HOME=${env.WORKSPACE}"]) {
sh 'neoload --version'
//sh 'neoload docker --all detach'
}
}
}
}
stage('Generate Test Report') {
steps {
withEnv(["HOME=${env.WORKSPACE}"]) {
sh "neoload test-results junitsla"
}
}
post {
always {
junit 'junit-sla.xml'
}
}
}
}
}
}
}