-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
178 lines (168 loc) · 6.58 KB
/
Jenkinsfile
File metadata and controls
178 lines (168 loc) · 6.58 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
@Library('shared-library') _
pipeline {
agent {
docker {
label 'memphis-jenkins-big-fleet,'
image 'python:3.11.9-bullseye'
args '-u root'
}
}
environment {
HOME = '/tmp'
SLACK_CHANNEL = '#jenkins-events'
}
stages {
stage('Prepare Environment') {
when {
anyOf {
allOf {
branch 'master'
triggeredBy 'UserIdCause' // Manual trigger on master
}
allOf {
branch 'latest'
}
}
}
steps {
script {
sh 'git config --global --add safe.directory $(pwd)'
env.GIT_AUTHOR = sh(script: 'git log -1 --pretty=%an', returnStdout: true).trim()
env.COMMIT_MESSAGE = sh(script: 'git log -1 --pretty=%B', returnStdout: true).trim()
def triggerCause = currentBuild.getBuildCauses().find { it._class == 'hudson.model.Cause$UserIdCause' }
env.TRIGGERED_BY = triggerCause ? triggerCause.userId : 'Commit'
}
sh """
export DEBIAN_FRONTEND=noninteractive
apt update -y
apt install -y python3 python3-pip python3-dev gcc make
# wget -qO - https://packages.confluent.io/deb/7.0/archive.key | apt-key add -
# add-apt-repository "deb https://packages.confluent.io/clients/deb \$(lsb_release -cs) main"
apt update
pip install --user pdm
pip install requests
"""
}
}
stage('Beta Release') {
when {
allOf {
branch 'master'
triggeredBy 'UserIdCause' // Manual "Build Now"
}
}
steps {
sh '''
sed -i -E 's/^(name *= *")superstream-clients(")/\\1superstream-clients-beta\\2/' pyproject.toml
'''
sh 'pip install --quiet build twine'
sh 'python -m build'
withCredentials([usernamePassword(credentialsId: 'superstream-pypi', usernameVariable: 'USR', passwordVariable: 'PSW')]) {
sh """
twine upload dist/* \
-u $USR \
-p $PSW
"""
}
}
}
stage('Prod Release') {
when {
branch 'latest'
}
steps {
sh 'pip install --quiet build twine'
sh 'python -m build'
withCredentials([usernamePassword(credentialsId: 'superstream-pypi', usernameVariable: 'USR', passwordVariable: 'PSW')]) {
sh """
twine upload dist/* \
-u $USR \
-p $PSW
"""
}
}
}
stage('Create Release'){
when {
branch 'latest'
}
steps {
sh 'pip install toml'
script {
def version = sh(
script: '''
python3 -c "import toml; print(toml.load('pyproject.toml')['project']['version'])"
''',
returnStdout: true
).trim()
env.versionTag = version
}
sh """
curl -L https://github.com/cli/cli/releases/download/v2.40.0/gh_2.40.0_linux_amd64.tar.gz -o gh.tar.gz
tar -xvf gh.tar.gz
mv gh_2.40.0_linux_amd64/bin/gh /usr/local/bin
rm -rf gh_2.40.0_linux_amd64 gh.tar.gz
"""
withCredentials([sshUserPrivateKey(keyFileVariable:'check',credentialsId: 'main-github')]) {
sh """
GIT_SSH_COMMAND='ssh -i $check -o StrictHostKeyChecking=no' git config --global user.email "jenkins@superstream.ai"
GIT_SSH_COMMAND='ssh -i $check -o StrictHostKeyChecking=no' git config --global user.name "Jenkins"
GIT_SSH_COMMAND='ssh -i $check -o StrictHostKeyChecking=no' git tag -a $versionTag -m "$versionTag"
GIT_SSH_COMMAND='ssh -i $check -o StrictHostKeyChecking=no' git push origin $versionTag
"""
}
withCredentials([string(credentialsId: 'gh_token', variable: 'GH_TOKEN')]) {
sh """
gh release create $versionTag dist/superstream_clients-${env.versionTag}.tar.gz --generate-notes
"""
}
}
}
}
post {
always {
cleanWs()
}
success {
script {
if (env.GIT_BRANCH == 'latest') {
sendSlackNotification('SUCCESS')
notifySuccessful()
}
}
}
failure {
script {
if (env.GIT_BRANCH == 'latest') {
sendSlackNotification('FAILURE')
notifyFailed()
}
}
}
aborted {
script {
if (env.BRANCH_NAME == 'latest') {
sendSlackNotification('ABORTED')
}
// Get the build log to check for the specific exception and retry job
AgentOfflineException()
}
}
}
}
def notifySuccessful() {
emailext (
subject: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':
Check console output and connection attributes at ${env.BUILD_URL}""",
to: 'tech-leads@superstream.ai'
)
}
def notifyFailed() {
emailext (
subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':
Check console output at ${env.BUILD_URL}""",
to: 'tech-leads@superstream.ai'
)
}