| 1 |
#!/usr/bin/env groovy |
| 2 |
|
| 3 |
/** |
| 4 |
* Jenkinsfile |
| 5 |
*/ |
| 6 |
pipeline { |
| 7 |
agent{ label 'exec'} |
| 8 |
options { |
| 9 |
buildDiscarder( |
| 10 |
// Only keep the 10 most recent builds |
| 11 |
logRotator(numToKeepStr:'10')) |
| 12 |
} |
| 13 |
environment { |
| 14 |
projectName = 'CvpRac' |
| 15 |
emailTo = '[email protected]' |
| 16 |
emailFrom = '[email protected]' |
| 17 |
} |
| 18 |
|
| 19 |
stages { |
| 20 |
|
| 21 |
stage ('Checkout') { |
| 22 |
steps { |
| 23 |
checkout scm |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
stage ('Install_Requirements') { |
| 28 |
steps { |
| 29 |
sh """ |
| 30 |
[[ -d venv ]] && rm -rf venv |
| 31 |
virtualenv --python=python2.7 venv |
| 32 |
source venv/bin/activate |
| 33 |
pip install --upgrade pip |
| 34 |
pip install -r requirements.txt |
| 35 |
pip install -r dev-requirements.txt |
| 36 |
pip install codecov |
| 37 |
""" |
| 38 |
// Stub dummy .cloudvision.yaml file |
| 39 |
writeFile file: "test/fixtures/cvp_nodes.yaml", text: "---\n- node: 10.81.111.9\n username: cvpadmin\n password: cvp123\n" |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
stage ('Check_style') { |
| 44 |
steps { |
| 45 |
sh """ |
| 46 |
source venv/bin/activate |
| 47 |
make clean |
| 48 |
[[ -d report ]] || mkdir report |
| 49 |
echo "exclude report" >> MANIFEST.in |
| 50 |
echo "exclude htmlcov" >> MANIFEST.in |
| 51 |
make check || true |
| 52 |
make pep8 | tee report/pep8_report.txt |
| 53 |
make pyflakes |
| 54 |
make pylint | tee report/pylint.out || true |
| 55 |
""" |
| 56 |
step([$class: 'WarningsPublisher', |
| 57 |
parserConfigurations: [[ |
| 58 |
parserName: 'Pep8', |
| 59 |
pattern: 'report/pep8_report.txt' |
| 60 |
], |
| 61 |
[ |
| 62 |
parserName: 'pylint', |
| 63 |
pattern: 'report/pylint.out' |
| 64 |
]], |
| 65 |
unstableTotalAll: '0', |
| 66 |
usePreviousBuildAsReference: true |
| 67 |
]) |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
stage ('System Test') { |
| 72 |
steps { |
| 73 |
sh """ |
| 74 |
source venv/bin/activate |
| 75 |
#make tests || true |
| 76 |
nosetests --with-xunit --all-modules --traverse-namespace --with-coverage --cover-package=cvprac --cover-inclusive --cover-html test/system/* || true |
| 77 |
""" |
| 78 |
} |
| 79 |
|
| 80 |
post { |
| 81 |
always { |
| 82 |
junit keepLongStdio: true, testResults: 'nosetests.xml' |
| 83 |
publishHTML target: [ |
| 84 |
reportDir: 'cover', |
| 85 |
reportFiles: 'index.html', |
| 86 |
reportName: 'Coverage Report' |
| 87 |
] |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
stage ('Docs') { |
| 93 |
steps { |
| 94 |
sh """ |
| 95 |
source venv/bin/activate |
| 96 |
PYTHONPATH=. pdoc --html --html-dir docs --overwrite cvprac |
| 97 |
""" |
| 98 |
} |
| 99 |
|
| 100 |
post { |
| 101 |
always { |
| 102 |
publishHTML target: [ |
| 103 |
reportDir: 'docs/cvprac', |
| 104 |
reportFiles: 'index.html', |
| 105 |
reportName: 'Module Documentation' |
| 106 |
] |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
stage ('Cleanup') { |
| 112 |
steps { |
| 113 |
sh 'rm -rf venv' |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
post { |
| 119 |
failure { |
| 120 |
mail body: "${env.JOB_NAME} (${env.BUILD_NUMBER}) ${env.projectName} build error " + |
| 121 |
"is here: ${env.BUILD_URL}\nStarted by ${env.BUILD_CAUSE}" , |
| 122 |
from: env.emailFrom, |
| 123 |
//replyTo: env.emailFrom, |
| 124 |
subject: "${env.projectName} ${env.JOB_NAME} (${env.BUILD_NUMBER}) build failed", |
| 125 |
to: env.emailTo |
| 126 |
} |
| 127 |
success { |
| 128 |
mail body: "${env.JOB_NAME} (${env.BUILD_NUMBER}) ${env.projectName} build successful\n" + |
| 129 |
"Started by ${env.BUILD_CAUSE}", |
| 130 |
from: env.emailFrom, |
| 131 |
//replyTo: env.emailFrom, |
| 132 |
subject: "${env.projectName} ${env.JOB_NAME} (${env.BUILD_NUMBER}) build successful", |
| 133 |
to: env.emailTo |
| 134 |
} |
| 135 |
} |
| 136 |
} |