forked from hubblestack/hubble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.pipeline
110 lines (104 loc) · 4.59 KB
/
.pipeline
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
def imgname = 'hubblestack/jenkins:centos-v1.0.8'
pipeline {
agent { docker { image "${imgname}" } }
options {
timestamps()
ansiColor 'xterm'
buildDiscarder(logRotator(numToKeepStr: '2', artifactNumToKeepStr: '1'))
}
environment {
PY_COLORS = 1
HS_PROFILE = 1
}
stages {
stage('setup') {
steps {
sh '''#!/bin/bash
source /etc/profile.d/kersplat.sh
pyenv local $PY_V
pyenv shell $PY_V
set -x -e
rm -rf vlib venv .pytest_cache
pip install --cache-dir ./pip.cache -t ./vlib virtualenv
PYTHONPATH=./vlib ./vlib/bin/virtualenv ./venv
source ./venv/bin/activate
pip install --cache-dir ./pip.cache -U pip
pip install --cache-dir ./pip.cache -U -r test-requirements.txt
'''
sh '''#!/bin/bash
# NOTE: CHANGE_TARGET and BRANCH_NAME are only populated on multibranch pipeline.
# For other environments, we have to fake it with 'origin/develop' and 'HEAD'
echo "CHANGE_TARGET=$CHANGE_TARGET BRANCH_NAME=$BRANCH_NAME"
/usr/bin/git fetch --no-tags --progress https://github.com/hubblestack/hubble.git +refs/heads/develop:refs/remotes/origin/develop
echo git branch -vva
git branch -vva
echo "LHS=$LHS RHS=$RHS"
LHS="origin/${CHANGE_TARGET:-develop}"
RHS="${BRANCH_NAME:+origin/}${BRANCH_NAME:-HEAD}"
if [[ $(git show -s --format='%s%n%b' "${LHS}..${RHS}") =~ LINT-FULL ]]
then find hubblestack -name "*.py"
else find hubblestack -name "*.py" -print0 | xargs -r0 git diff --name-only "$LHS" "$RHS"
fi > relevant-files.txt
'''
sh '''mkdir -vp tests/unittests/output'''
}
}
stage('lint/test') {
parallel {
stage('pytest') {
steps {
sh '''#!/bin/bash
source ./venv/bin/activate
pytest --log-cli-level INFO tests/unittests --html=tests/unittests/output/pytest.html
x=$?
cp tests/unittests/output/combined.svg tests/unittests/output/profile-diagram.svg
exit $x
'''
}
}
stage('pylint') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh '''#!/bin/bash
source ./venv/bin/activate
< relevant-files.txt xargs -r pylint --output-format=json \
> tests/unittests/output/pylint.json
x=$?
python ./tests/automation/pylint-json-to-html tests/unittests/output/pylint.json
exit $x
'''
}
}
}
stage('bandit') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh '''#!/bin/bash
source ./venv/bin/activate
< relevant-files.txt xargs -r bandit -lif html \
> tests/unittests/output/bandit.html
x=$?
cp tests/static/bandit.css tests/unittests/output/bandit.css
sed -i -e '/<style/,/<.style/c<link rel="stylesheet" href="bandit.css">' \
tests/unittests/output/bandit.html
exit $x
'''
}
}
}
}
}
}
post {
always {
publishHTML (target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'tests/unittests/output',
reportFiles: 'pytest.html, coverage/index.html, pylint.html, profile-diagram.svg, bandit.html',
reportName: "Test Reports"
])
}
}
}