-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
141 lines (134 loc) · 5.7 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
pipeline {
agent {
kubernetes {
// the shared pod template defined on the Jenkins server config
inheritFrom 'shared'
// pod template defined in molgenis/molgenis-jenkins-pipeline repository
yaml libraryResource("pod-templates/python-3.10.yaml")
}
}
stages {
stage('Prepare') {
steps {
script {
env.GIT_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
}
container('vault') {
script {
env.PYPI_USERNAME = sh(script: 'vault read -field=token_username secret/ops/account/pypi', returnStdout: true)
env.PYPI_PASSWORD = sh(script: 'vault read -field=API_token secret/ops/account/pypi', returnStdout: true)
env.TESTPYPI_USERNAME = sh(script: 'vault read -field=token_username secret/ops/account/testpypi', returnStdout: true)
env.TESTPYPI_PASSWORD = sh(script: 'vault read -field=API_token secret/ops/account/testpypi', returnStdout: true)
env.GITHUB_TOKEN = sh(script: 'vault read -field=value secret/ops/token/github', returnStdout: true)
env.SONAR_TOKEN = sh(script: 'vault read -field=value secret/ops/token/sonar', returnStdout: true)
}
}
container('python') {
script {
sh "pip install tox"
sh "pip install pre-commit"
sh "pre-commit install"
}
}
}
}
stage('Build: [ pull request ]') {
when {
changeRequest()
}
steps {
container('python') {
sh "tox"
sh "pre-commit run --all-files"
}
container('sonar') {
sh "sonar-scanner -Dsonar.github.oauth=${env.GITHUB_TOKEN} -Dsonar.pullrequest.base=${CHANGE_TARGET} -Dsonar.pullrequest.branch=${BRANCH_NAME} -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.provider=GitHub -Dsonar.pullrequest.github.repository=molgenis/molgenis-py-bbmri-eric"
}
}
}
stage('Build: [ main ]') {
when {
branch 'main'
}
steps {
milestone 1
container('python') {
sh "tox"
sh "pre-commit run --all-files"
}
container('sonar') {
sh "sonar-scanner"
}
}
}
stage('Release: [ main ]') {
when {
branch 'main'
}
environment {
REPOSITORY = 'molgenis/molgenis-py-bbmri-eric'
}
steps {
timeout(time: 15, unit: 'MINUTES') {
script {
env.RELEASE_SCOPE = input(
message: 'Do you want to release?',
ok: 'Release to TestPyPi',
parameters: [
choice(choices: 'patch\nminor\nmajor', description: '', name: 'RELEASE_SCOPE')
]
)
}
}
milestone 2
container('python') {
sh "git remote set-url origin https://${GITHUB_TOKEN}@github.com/${REPOSITORY}.git"
sh "git checkout -f main"
sh "git fetch --tags"
// bump the version based on the last tag and create a new tag
sh "pip install bumpversion"
script {
env.NEW_PACKAGE_VERSION = sh(script: "sh bump-version.sh", returnStdout: true).trim()
}
// undo the formatting changes made by bumpversion to setup.cfg
sh "git checkout ."
// build and publish the release
sh "tox -e build"
sh "tox -e publish -- --repository testpypi --username ${TESTPYPI_USERNAME} --password ${TESTPYPI_PASSWORD}"
// push the new tag to molgenis/molgenis-py-bbmri-eric
sh "git push --tags origin main"
}
timeout(time: 60, unit: 'MINUTES') {
script {
env.RELEASE_SCOPE = input(
message: "Test the release at: \nhttps://test.pypi.org/project/molgenis-py-bbmri-eric/${NEW_PACKAGE_VERSION}/ \nContinue the release if it's ok, abort otherwise.",
ok: 'Release to PyPi'
)
}
}
container('python') {
// do the actual release to PyPi
sh "tox -e publish -- --repository pypi --username ${PYPI_USERNAME} --password ${PYPI_PASSWORD}"
hubotSend(message: "molgenis-py-bbmri-eric ${NEW_PACKAGE_VERSION} has been released! :tada: https://pypi.org/project/molgenis-py-bbmri-eric/", status:'SUCCESS')
}
}
}
}
post{
always {
junit 'reports/junit.xml'
}
success {
notifySuccess()
}
failure {
notifyFailed()
}
}
}
def notifySuccess() {
hubotSend(message: 'Build success', status:'INFO', site: 'slack-pr-app-team')
}
def notifyFailed() {
hubotSend(message: 'Build failed', status:'ERROR', site: 'slack-pr-app-team')
}