-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
149 lines (143 loc) · 4.8 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
142
143
144
145
146
147
148
149
def GITLAB_STATE_SUCCESS = 'success'
def GITLAB_STATE_FAILURE = 'failed'
def PYTHON_VERSION = '3.8' // TODO: could add this to dockerfile buildArgs
def ARTIFACTORY_SERVER_ID = 'ARTIFACTORY_SERVER'
// TODO: can set this to the stages Setup section and
// dynamically set based on agent type
String PATH_WORKAROUD = '' // windows
// String PATH_WORKAROUD = '$env:PATH="/root/.local/bin:"+$env:PATH' // unix
pipeline {
agent {
dockerfile {
filename 'Dockerfile.windows'
reuseNode true
// TODO: can move this to the stages section and
// dynamically set user based on agent type
args '-u ContainerAdministrator' // windows
// args '-u root' // unix
// Agent label
label '<if-you-use-agent-labels>'
}
}
options {
gitLabConnection('GitLabAPIConnection')
gitlabBuilds(builds: ['lint', 'test', 'build'])
timestamps()
timeout(time: 5, unit: 'MINUTES') // timeout on whole pipeline job
ansiColor('xterm') // color the console output in jenkins ui
}
stages {
stage('Setup') {
steps {
pwsh """
$PATH_WORKAROUD
python --version
tox --version
hatch --version
"""
}
}
stage('Lint') {
steps {
pwsh """
$PATH_WORKAROUD
tox -e lint
"""
}
post {
failure {
updateGitlabCommitStatus name: 'lint', state: "$GITLAB_STATE_FAILURE"
}
success {
updateGitlabCommitStatus name: 'lint', state: "$GITLAB_STATE_SUCCESS"
}
}
}
stage('Test') {
steps {
pwsh """
$PATH_WORKAROUD
tox
"""
}
post {
failure {
updateGitlabCommitStatus name: 'test', state: "$GITLAB_STATE_FAILURE"
}
success {
updateGitlabCommitStatus name: 'test', state: "$GITLAB_STATE_SUCCESS"
}
}
}
stage('Build') {
steps {
pwsh """
$PATH_WORKAROUD
hatch build
"""
}
post {
failure {
updateGitlabCommitStatus name: 'build', state: "$GITLAB_STATE_FAILURE"
}
success {
updateGitlabCommitStatus name: 'build', state: "$GITLAB_STATE_SUCCESS"
}
}
}
stage('Publish') {
when { tag 'v*' }
steps {
rtServer(
id: "$ARTIFACTORY_SERVER_ID",
url: "https://${ArtifactoryServerUrl}/artifactory",
credentialsId: 'ArtifactoryCreds'
)
script {
pwsh "$PATH_WORKAROUD; hatch version >> ver.txt"
def PACKAGE_VERSION = pwsh(
script: 'Select-String -Path "ver.txt" -Pattern "\\d.*" -Raw' , // "\d.*""
returnStdout: true
).replaceAll('\\s', '') // strip the rogue newline
echo "Package version is: '$PACKAGE_VERSION'"
rtUpload(
serverId: "$ARTIFACTORY_SERVER_ID",
spec: """{
"files": [
{
"pattern": "dist/",
"target": "<the-pypi>/$PACKAGE_VERSION/"
}
]
}"""
)
}
rtPublishBuildInfo (
serverId: "$ARTIFACTORY_SERVER_ID"
)
}
post {
failure {
updateGitlabCommitStatus name: 'publish', state: "$GITLAB_STATE_FAILURE"
}
success {
updateGitlabCommitStatus name: 'publish', state: "$GITLAB_STATE_SUCCESS"
}
}
}
}
post {
always {
jiraSendBuildInfo()
junit 'build/test-*.xml'
}
changed {
emailext body: '$PROJECT_NAME - Build $BUILD_DISPLAY_NAME: $BUILD_STATUS<br><br>Check console output at $BUILD_URL to view the results.',
recipientProviders: [culprits(), requestor()],
subject: '$PROJECT_NAME - Build $BUILD_DISPLAY_NAME: $BUILD_STATUS'
}
cleanup {
cleanWs()
}
}
}