-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
121 lines (118 loc) · 4.66 KB
/
Jenkinsfile
File metadata and controls
121 lines (118 loc) · 4.66 KB
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
pipeline {
agent { label 'docker' }
environment {
AGENT_TAG = env.BRANCH_NAME.replaceFirst('^master$', 'latest')
AGENT_NAME = "${env.DOCKER_REGISTRY}/gros-data-gathering"
AGENT_IMAGE = "${env.AGENT_NAME}:${env.AGENT_TAG}"
GITLAB_TOKEN = credentials('data-gathering-gitlab-token')
SCANNER_HOME = tool name: 'SonarQube Scanner 3', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
}
options {
gitLabConnection('gitlab')
buildDiscarder(logRotator(numToKeepStr: '10'))
}
triggers {
gitlab(triggerOnPush: true, triggerOnMergeRequest: true, branchFilterType: 'All', secretToken: env.GITLAB_TOKEN)
cron('H H * * H/3')
}
post {
failure {
updateGitlabCommitStatus name: env.JOB_NAME, state: 'failed'
}
aborted {
updateGitlabCommitStatus name: env.JOB_NAME, state: 'canceled'
}
always {
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, keepAll: true, reportDir: 'mypy-report/', reportFiles: 'index.html', reportName: 'Typing', reportTitles: ''])
junit allowEmptyResults: true, testResults: 'mypy-report/junit.xml'
archiveArtifacts 'controller/openapi.json,scraper/agent/openapi.json,schema/**/*.json'
}
}
stages {
stage('Start') {
when {
not {
triggeredBy 'TimerTrigger'
}
}
steps {
updateGitlabCommitStatus name: env.JOB_NAME, state: 'running'
}
}
stage('Build') {
steps {
checkout scm
withCredentials([file(credentialsId: 'upload-server-certificate', variable: 'SERVER_CERTIFICATE')]) {
withCredentials([file(credentialsId: 'agent-environment', variable: 'AGENT_ENVIRONMENT')]) {
sh 'rm -f certs/wwwgros.crt'
sh 'cp $SERVER_CERTIFICATE certs/wwwgros.crt'
sh 'cp $AGENT_ENVIRONMENT env'
sh 'chmod 444 certs/wwwgros.crt'
sh 'echo $(grep __version__ gatherer/__init__.py | sed -E "s/__version__ = .([0-9\\.]+)./\\1/") > .version'
sh 'echo $(cat .version)-$BRANCH_NAME-$(git show-ref $BRANCH_NAME | cut -f1 -d\' \' | head -n 1) > VERSION'
sh 'docker build -t $AGENT_IMAGE .'
}
}
}
}
stage('Push') {
steps {
sh 'docker push $AGENT_IMAGE'
}
}
stage('SonarQube Analysis') {
steps {
withPythonEnv('System-CPython-3') {
pysh 'make setup_analysis'
pysh 'make mypy_html'
pysh 'make pylint > pylint-report.txt'
}
withSonarQubeEnv('SonarQube') {
sh '${SCANNER_HOME}/bin/sonar-scanner -Dsonar.projectKey=data-gathering:$BRANCH_NAME -Dsonar.projectName="Data gathering $BRANCH_NAME"'
}
}
}
stage('Push versioned') {
when { branch 'master' }
steps {
sh 'docker tag $AGENT_IMAGE "$AGENT_NAME:$(cat .version)"'
sh 'docker push "$AGENT_NAME:$(cat .version)"'
}
}
stage('Build pypi') {
agent {
docker {
image "${env.AGENT_IMAGE}"
reuseNode true
}
}
steps {
sh 'make setup_release'
sh 'make build'
sh 'mkdir -p build/wheel'
sh 'grep "#egg=" requirements.txt | xargs pip wheel -w build/wheel --no-deps'
}
}
stage('Push pypi') {
when { branch 'master' }
steps {
withPythonEnv('System-CPython-3') {
pysh 'make setup_release'
withCredentials([usernamePassword(credentialsId: 'pypi-credentials', passwordVariable: 'TWINE_PASSWORD', usernameVariable: 'TWINE_USERNAME'), string(credentialsId: 'pypi-repository', variable: 'TWINE_REPOSITORY_URL'), file(credentialsId: 'pypi-certificate', variable: 'TWINE_CERT')]) {
pysh 'python -m twine upload dist/* build/wheel/*'
}
}
}
}
stage('Status') {
when {
not {
triggeredBy 'TimerTrigger'
}
}
steps {
updateGitlabCommitStatus name: env.JOB_NAME, state: 'success'
}
}
}
}