forked from spacetelescope/jwql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
94 lines (81 loc) · 4.05 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
// JWQL Jenkinsfile
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// Authors:
// --------
// - Matthew Bourque
// - Lauren Chambers
// - Joshua Alexander
// - Sara Ogaz
// - Matt Rendina
//
// Notes:
// ------
// - More info here: https://github.com/spacetelescope/jenkinsfile_ci_examples
// - Syntax defined here: https://github.com/spacetelescope/jenkins_shared_ci_utils
//
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// scm_checkout() does the following:
// 1. Disables pipeline execution if [skip ci] or [ci skip] is present in the
// commit message, letting users exclude individual commits from CI
// 2. Clones the Git repository
// 3. Creates a local cache of the repository to avoid commit drift between tasks
// (i.e. Each stage is guaranteed to receive the same source code regardless of
// commits taking place after the pipeline has started.)
if (utils.scm_checkout()) return
// Establish OS and Python version variables for the matrix
matrix_os = ["linux-stable"] // (Note that Jenkins can only be run with Linux, not MacOSX/Windows)
matrix_python = ["3.6"]
// Set up the matrix of builds
matrix = []
// Define IDs that live on the Jenkins server (here, for CodeCov and PyPI)
withCredentials([
string(credentialsId: 'jwql-codecov', variable: 'codecov_token'),
usernamePassword(credentialsId:'jwql-pypi', usernameVariable: 'pypi_username', passwordVariable: 'pypi_password')])
// Iterate over the above variables to define the build matrix.
{
for (os in matrix_os) {
for (python_ver in matrix_python) {
// Define each build configuration, copying and overriding values as necessary.
// Define a string variable to reflect the python version of this build
env_py = "_python_${python_ver}".replace(".", "_")
// Create a new build configuration
bc = new BuildConfig()
// Define the OS (only "linux-stable" used here)
bc.nodetype = os
// Give the build configuration a name. This string becomes the
// stage header on Jenkins' UI. Keep it short!
bc.name = "debug-${os}-${env_py}"
// (Required) Define what packages to include in the base conda environment.
// This specification also tells Jenkins to spin up a new conda environment for
// your build, rather than using the default environment.
bc.conda_packages = ["python=${python_ver}"]
// Execute a series of commands to set up the build, including
// any packages that have to be installed with pip
bc.build_cmds = [
"conda env update --file=environment${env_py}.yml", // Update env from file
"pip install codecov pytest-cov", // Install additional packages
"python setup.py install", // Install JWQL package
"python setup.py sdist bdist_wheel" // Build JWQL pacakge wheel for PyPI
]
// Execute a series of test commands
bc.test_cmds = [
// Run pytest
"pytest ./jwql/tests/ -s --junitxml=results.xml --cov=./jwql/ --cov-report=xml:coverage.xml",
// Add a truly magical command that makes Jenkins work for Python 3.5
"sed -i 's/file=\"[^\"]*\"//g;s/line=\"[^\"]*\"//g;s/skips=\"[^\"]*\"//g' results.xml",
// Define CodeCov token
"codecov --token=${codecov_token}",
// Move the CodeCov report to a different dir to not confuse Jenkins about results.xml
"mkdir -v reports",
"mv -v coverage.xml reports/coverage.xml",
// Update the package wheel to PYPI
"twine upload -u '${pypi_username}' -p '${pypi_password}' --repository-url https://upload.pypi.org/legacy/ --skip-existing dist/*"]
// Add the build to the matrix
matrix += bc
}
}
// Submit the build configurations and execute them in parallel
utils.run(matrix)
}