-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
102 lines (101 loc) · 3.76 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
#!/usr/bin/env groovy
pipeline {
agent any
options {
copyArtifactPermission('*');
}
environment {
POETRY = '/opt/python-3.9/bin/poetry'
VERSION = sh(
returnStdout: true,
script: 'git describe --tags --abbrev=0'
).trim()
no_proxy = "bitbucket.usit.uio.no"
}
stages {
stage('Test and build python package') {
agent { label 'python3' }
stages {
stage('Install dependencies') {
steps {
// Set version number from git tag
sh "${POETRY} version ${VERSION}"
sh "${POETRY} install"
}
}
stage('Test, lint and build') {
parallel {
stage('Run linting') {
steps {
script {
// Allow linting to fail
// TODO remove catchError after cleaning up codet describe --tags --dirty=+
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh "${POETRY} -q check"
sh "${POETRY} run pylint evalg"
sh "${POETRY} run black --check --diff evalg"
}
}
}
}
stage('Run type checks') {
steps {
sh "${POETRY} run mypy -p evalg"
}
}
stage('Run tests') {
steps {
sh "${POETRY} run pytest --junitxml=junit.xml --cov=evalg --cov-report xml:coverage.xml --cov-report term"
}
}
stage('Build wheel') {
steps {
sh "${POETRY} build -f wheel"
archiveArtifacts artifacts: 'dist/evalg-*.whl'
}
}
}
}
}
post {
always {
junit '**/junit.xml'
publishCoverage adapters: [coberturaAdapter(path: '**/coverage.xml')]
}
cleanup {
sh('rm -vf junit.xml')
sh('rm -vf coverage.xml')
sh('rm -vrf build dist')
}
}
}
stage('Build and deploy docker image') {
agent { label 'docker' }
when { branch 'main' }
environment {
REPO = 'harbor.uio.no'
PROJECT = 'it-usit-int-drift'
APP_NAME = 'evalg-backend'
CONTAINER = "${REPO}/${PROJECT}/${APP_NAME}"
IMAGE_TAG = "${CONTAINER}:${VERSION}"
}
stages {
stage('Build docker images') {
steps {
script {
docker_image = docker.build("${IMAGE_TAG}", '--pull --no-cache -f ./Dockerfile .')
docker_image.push()
docker_image.push('staging')
docker_image.push('latest')
}
}
}
}
post {
cleanup {
sh("docker rmi -f \$(docker images --filter 'reference=${IMAGE_TAG}' -q)")
}
}
}
}
}