-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
181 lines (148 loc) · 3.96 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env groovy
def job_desc = """
Jenkins multibranch job for 'workstation'
<br/>
<a href='https://github.com/nvtkaszpir/workstation'>github</a>
"""
pipeline {
agent { label 'libvirt' }
options {
timeout(time: 4, unit: 'HOURS')
disableConcurrentBuilds()
ansiColor('xterm')
timestamps() // breaks ansiColor plugin
lock resource: 'workstation'
}
// notice that parameters are dynamically updated in first stage
// parameters {
// }
environment {
PYENV_VIRTUALENV_DISABLE_PROMPT=1
}
stages {
stage('Reconfig job'){
steps {
script{
def job = Jenkins.instance.getItemByFullName(job_name)
// change description
def pr_desc = ""
if ( env.CHANGE_ID != null) {
pr_desc += "<br/>"
pr_desc += "<br/>"
pr_desc += "<br/>"
pr_desc += "<h2>Change URL: <a href='${env.CHANGE_URL}'>${env.CHANGE_TITLE}</a></h2><br/>"
}
job.setDescription(job_desc + pr_desc)
job.save()
}
}
}
stage('review') {
when {
// run review step if this is PR and the PR is not from repo owner
expression { (env.CHANGE_ID != null) && (env.CHANGE_AUTHOR != 'nvtkaszpir') }
}
steps {
script {
approve = input(message: "Continue with build?", submitter: 'kaszpir', parameters: [
choice(
name: 'result',
choices: ["No", "Yes"].join("\n"),
description: "Please review the code and continue build if it looks good."
)
])
if (approve == "Yes") {
println "Review stage approved."
}
else
{
currentBuild.result = 'ABORTED'
error("Review stage not approved.")
}
}
}
}
stage('prep') {
parallel {
stage('markdownlint') {
steps {
sh '''#!/bin/bash -l
docker run -v $PWD:/markdown:ro 06kellyjac/markdownlint-cli .
'''
}
}
stage('pyenv') {
steps {
sh '''#!/bin/bash -l
# python version is taken from .python-version
pyenv install -s
pyenv virtualenv ws
pyenv activate ws
pip install --upgrade pip==21.0.1
hash -r
pip install lxml # needs to be before requirements :/
pip install -r requirements.txt
'''
}
}
stage('vagrant info'){
steps {
sh '''#!/bin/bash -l
export | sort
vagrant version
vagrant plugin list | grep vagrant-libvirt \
|| vagrant plugin install vagrant-libvirt --plugin-version 0.3.0
'''
}
}
}
}
stage('quick-tests') {
parallel {
stage('yamllint'){
steps {
sh '''#!/bin/bash -l
pyenv activate ws
yamllint -f parsable . | yamllint-junit -o reports/yamllint-junit.xml
'''
junit 'reports/yamllint-junit.xml'
}
}
stage('ansible-lint'){
steps {
sh '''#!/bin/bash -l
pyenv activate ws
ansible-lint desktop.yml | ansible-lint-junit -o reports/ansible-lint.xml
'''
junit 'reports/ansible-lint.xml'
}
}
}
}
stage('test'){
steps {
sh '''#!/bin/bash -l
pyenv activate ws
export VM_TEARDOWN=true
scripts/test_in_vagrant.sh
'''
}
post {
always {
sh '''#!/bin/bash -l
vagrant destroy -f
'''
}
}
}
}
post {
always {
sh '''#!/bin/bash -l
pyenv virtualenv-delete -f ws
'''
archiveArtifacts allowEmptyArchive: true, artifacts: 'reports/**/*.*', excludes: '**/*.gitkeep', fingerprint: true
deleteDir()
}
}
}