forked from cognitedata/cognite-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
80 lines (76 loc) · 3.51 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
@Library('[email protected]') _
def label = "cognite-sdk-python-${UUID.randomUUID().toString()}"
podTemplate(
label: label,
annotations: [
podAnnotation(key: "jenkins/build-url", value: env.BUILD_URL ?: ""),
podAnnotation(key: "jenkins/github-pr-url", value: env.CHANGE_URL ?: ""),
],
containers: [
containerTemplate(name: 'python',
image: 'python:3.6.4',
command: '/bin/cat -',
resourceRequestCpu: '1000m',
resourceRequestMemory: '800Mi',
resourceLimitCpu: '1000m',
resourceLimitMemory: '800Mi',
envVars: [envVar(key: 'PYTHONPATH', value: '/usr/local/bin')],
ttyEnabled: true),
],
volumes: [
secretVolume(secretName: 'jenkins-docker-builder', mountPath: '/jenkins-docker-builder', readOnly: true),
secretVolume(secretName: 'pypi-credentials', mountPath: '/pypi', readOnly: true),
configMapVolume(configMapName: 'codecov-script-configmap', mountPath: '/codecov-script'),
],
envVars: [
secretEnvVar(key: 'COGNITE_TEST_API_KEY', secretName: 'ml-test-api-key', secretKey: 'testkey.txt'),
secretEnvVar(key: 'CODECOV_TOKEN', secretName: 'codecov-token-cognite-sdk-python', secretKey: 'token.txt'),
// /codecov-script/upload-report.sh relies on the following
// Jenkins and Github environment variables.
envVar(key: 'BRANCH_NAME', value: env.BRANCH_NAME),
envVar(key: 'BUILD_NUMBER', value: env.BUILD_NUMBER),
envVar(key: 'BUILD_URL', value: env.BUILD_URL),
envVar(key: 'CHANGE_ID', value: env.CHANGE_ID),
]) {
node(label) {
def gitCommit
container('jnlp') {
stage('Checkout') {
checkout(scm)
gitCommit = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
}
}
container('python') {
stage('Install pipenv') {
sh("pip3 install pipenv")
}
stage('Install dependencies') {
sh("pipenv sync --dev")
}
stage('Test and coverage report') {
sh("pipenv run pytest --cov-report xml:coverage.xml --cov=cognite --junitxml=test-report.xml || true")
junit(allowEmptyResults: true, testResults: '**/test-report.xml')
summarizeTestResults()
}
stage('Upload coverage reports') {
sh 'bash </codecov-script/upload-report.sh'
step([$class: 'CoberturaPublisher', coberturaReportFile: 'coverage.xml'])
}
stage('Build') {
sh("pipenv run python3 code_parser.py --remove-type-hints --suppress-warning")
sh("pipenv run python3 -m black ./cognite -l 120")
sh("python3 setup.py sdist")
sh("python3 setup.py bdist_wheel")
}
def pipVersion = sh(returnStdout: true, script: 'pipenv run yolk -V cognite-sdk | sort -n | tail -1 | cut -d\\ -f 2').trim()
def currentVersion = sh(returnStdout: true, script: 'sed -n -e "/^__version__/p" cognite/__init__.py | cut -d\\" -f2').trim()
println("This version: " + currentVersion)
println("Latest pip version: " + pipVersion)
if (env.BRANCH_NAME == 'master' && currentVersion != pipVersion) {
stage('Release') {
sh("pipenv run twine upload --config-file /pypi/.pypirc dist/*")
}
}
}
}
}