Skip to content

Commit 0b0ae06

Browse files
aline pipeline
1 parent c4f7778 commit 0b0ae06

File tree

1 file changed

+94
-124
lines changed

1 file changed

+94
-124
lines changed

Jenkinsfile

Lines changed: 94 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@Library('shared-library') _
12

23
pipeline {
34

@@ -39,9 +40,9 @@ pipeline {
3940

4041

4142
stage('Beta Release') {
42-
// when {
43-
// branch '*-beta'
44-
// }
43+
when {
44+
branch 'master'
45+
}
4546
steps {
4647
script {
4748
def version = readFile('version-beta.conf').trim()
@@ -56,15 +57,7 @@ pipeline {
5657
'''
5758
sh 'pip install --quiet build twine'
5859
sh 'python -m build'
59-
sh 'ls dist/'
6060
withCredentials([usernamePassword(credentialsId: 'superstream-pypi', usernameVariable: 'USR', passwordVariable: 'PSW')]) {
61-
// sh """
62-
// python3 patch/patch.py --src "dist/superstream_confluent_kafka_beta-${env.versionTag}-cp311-cp311-linux_x86_64.whl" --output "dist/" --prefix "superstream_confluent_kafka_beta-${env.versionTag}"
63-
// """
64-
// sh"""
65-
// rm dist/superstream_confluent_kafka_beta-${env.versionTag}-cp311-cp311-linux_x86_64.whl
66-
// /tmp/.local/bin/pdm publish --no-build --username $USR --password $PSW
67-
// """
6861
sh """
6962
twine upload dist/* \
7063
-u $USR \
@@ -73,126 +66,103 @@ pipeline {
7366
}
7467
}
7568
}
76-
// stage('Prod Release') {
77-
// when {
78-
// branch '2.4.0'
79-
// }
80-
// steps {
81-
// script {
82-
// def version = readFile('version.conf').trim()
83-
// env.versionTag = version
84-
// echo "Using version from version.conf: ${env.versionTag}"
85-
// }
86-
// sh "sed -i \'s/version = \"[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+\"/version = \"${env.versionTag}\"/g\' pyproject.toml"
87-
// sh """
88-
// C_INCLUDE_PATH=/usr/include/librdkafka LIBRARY_PATH=/usr/include/librdkafka /tmp/.local/bin/pdm build
89-
// """
90-
// withCredentials([usernamePassword(credentialsId: 'superstream-pypi', usernameVariable: 'USR', passwordVariable: 'PSW')]) {
91-
// sh """
92-
// python3 patch/patch.py --src "dist/superstream_confluent_kafka-${env.versionTag}-cp311-cp311-linux_x86_64.whl" --output "dist/" --prefix "superstream_confluent_kafka-${env.versionTag}"
93-
// """
94-
// sh"""
95-
// rm dist/superstream_confluent_kafka-${env.versionTag}-cp311-cp311-linux_x86_64.whl
96-
// /tmp/.local/bin/pdm publish --no-build --username $USR --password $PSW
97-
// """
98-
// }
99-
// }
100-
// }
101-
// stage('Create Release'){
102-
// when {
103-
// branch '2.4.0'
104-
// }
105-
// steps {
106-
// sh """
107-
// curl -L https://github.com/cli/cli/releases/download/v2.40.0/gh_2.40.0_linux_amd64.tar.gz -o gh.tar.gz
108-
// tar -xvf gh.tar.gz
109-
// mv gh_2.40.0_linux_amd64/bin/gh /usr/local/bin
110-
// rm -rf gh_2.40.0_linux_amd64 gh.tar.gz
111-
// """
112-
// withCredentials([sshUserPrivateKey(keyFileVariable:'check',credentialsId: 'main-github')]) {
113-
// sh """
114-
// GIT_SSH_COMMAND='ssh -i $check -o StrictHostKeyChecking=no' git config --global user.email "[email protected]"
115-
// GIT_SSH_COMMAND='ssh -i $check -o StrictHostKeyChecking=no' git config --global user.name "Jenkins"
116-
// GIT_SSH_COMMAND='ssh -i $check -o StrictHostKeyChecking=no' git tag -a $versionTag -m "$versionTag"
117-
// GIT_SSH_COMMAND='ssh -i $check -o StrictHostKeyChecking=no' git push origin $versionTag
118-
// """
119-
// }
120-
// withCredentials([string(credentialsId: 'gh_token', variable: 'GH_TOKEN')]) {
121-
// sh """
122-
// gh release create $versionTag dist/superstream_confluent_kafka-${env.versionTag}.tar.gz --generate-notes
123-
// """
124-
// }
125-
// }
126-
// }
69+
stage('Prod Release') {
70+
when {
71+
branch 'latest'
72+
}
73+
steps {
74+
script {
75+
def version = readFile('version.conf').trim()
76+
env.versionTag = version
77+
echo "Using version from version.conf: ${env.versionTag}"
78+
}
79+
sh """
80+
sed -i 's/version = "[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+"/version = "${env.versionTag}"/g' pyproject.toml
81+
"""
82+
sh 'pip install --quiet build twine'
83+
sh 'python -m build'
84+
withCredentials([usernamePassword(credentialsId: 'superstream-pypi', usernameVariable: 'USR', passwordVariable: 'PSW')]) {
85+
sh """
86+
twine upload dist/* \
87+
-u $USR \
88+
-p $PSW
89+
"""
90+
}
91+
}
92+
}
93+
stage('Create Release'){
94+
when {
95+
branch 'latest'
96+
}
97+
steps {
98+
sh """
99+
curl -L https://github.com/cli/cli/releases/download/v2.40.0/gh_2.40.0_linux_amd64.tar.gz -o gh.tar.gz
100+
tar -xvf gh.tar.gz
101+
mv gh_2.40.0_linux_amd64/bin/gh /usr/local/bin
102+
rm -rf gh_2.40.0_linux_amd64 gh.tar.gz
103+
"""
104+
withCredentials([sshUserPrivateKey(keyFileVariable:'check',credentialsId: 'main-github')]) {
105+
sh """
106+
GIT_SSH_COMMAND='ssh -i $check -o StrictHostKeyChecking=no' git config --global user.email "[email protected]"
107+
GIT_SSH_COMMAND='ssh -i $check -o StrictHostKeyChecking=no' git config --global user.name "Jenkins"
108+
GIT_SSH_COMMAND='ssh -i $check -o StrictHostKeyChecking=no' git tag -a $versionTag -m "$versionTag"
109+
GIT_SSH_COMMAND='ssh -i $check -o StrictHostKeyChecking=no' git push origin $versionTag
110+
"""
111+
}
112+
withCredentials([string(credentialsId: 'gh_token', variable: 'GH_TOKEN')]) {
113+
sh """
114+
gh release create $versionTag dist/superstream_confluent_kafka-${env.versionTag}.tar.gz --generate-notes
115+
"""
116+
}
117+
}
118+
}
127119
}
128120
post {
129121
always {
130122
cleanWs()
131123
}
132-
// success {
133-
// script {
134-
// if (env.BRANCH_NAME == '2.4.0') {
135-
// sendSlackNotification('SUCCESS')
136-
// }
137-
// }
138-
// }
139-
// failure {
140-
// script {
141-
// if (env.BRANCH_NAME == '2.4.0') {
142-
// sendSlackNotification('FAILURE')
143-
// }
144-
// }
145-
// }
146-
// aborted {
147-
// script {
148-
// if (env.BRANCH_NAME == '2.4.0') {
149-
// sendSlackNotification('ABORTED')
150-
// }
151-
// // Get the build log to check for the specific exception
152-
// def buildLog = currentBuild.rawBuild.getLog(50)
153-
// // Log the build log for debugging purposes (you can remove this once confirmed)
154-
// echo "Build Log:\n${buildLog.join('\n')}"
155-
// // Check if the log contains the specific exception using a regular expression
156-
// if (buildLog.find { it =~ /org\.jenkinsci\.plugins\.workflow\.support\.steps\.AgentOfflineException/ }) {
157-
// echo 'AgentOfflineException found, retrying the build...'
158-
// // Check if the build has parameters and rerun the job accordingly
159-
// def paramsList = currentBuild.rawBuild.getAction(hudson.model.ParametersAction)?.parameters
160-
// if (paramsList) {
161-
// build(job: env.JOB_NAME, parameters: paramsList)
162-
// } else {
163-
// echo 'No parameters found, rerunning without parameters'
164-
// build(job: env.JOB_NAME)
165-
// }
166-
// } else {
167-
// echo 'Abort not related to AgentOfflineException, not retrying.'
168-
// }
169-
// }
170-
// }
124+
success {
125+
script {
126+
if (env.GIT_BRANCH == 'latest') {
127+
sendSlackNotification('SUCCESS')
128+
notifySuccessful()
129+
}
130+
}
131+
}
132+
133+
failure {
134+
script {
135+
if (env.GIT_BRANCH == 'latest') {
136+
sendSlackNotification('FAILURE')
137+
notifyFailed()
138+
}
139+
}
140+
}
141+
aborted {
142+
script {
143+
if (env.BRANCH_NAME == 'latest') {
144+
sendSlackNotification('ABORTED')
145+
}
146+
// Get the build log to check for the specific exception and retry job
147+
AgentOfflineException()
148+
}
149+
}
171150
}
172151
}
173152

174-
// SlackSend Function
175-
def sendSlackNotification(String jobResult) {
176-
def jobUrl = env.BUILD_URL
177-
def messageDetail = env.COMMIT_MESSAGE ? "Commit/PR by @${env.GIT_AUTHOR}:\n${env.COMMIT_MESSAGE}" : "No commit message available."
178-
def projectName = env.JOB_NAME
179-
180-
// Define the color based on the job result
181-
def color = jobResult == 'SUCCESS' ? 'good' : (jobResult == 'ABORTED' ? '#808080' : 'danger')
182-
183-
slackSend (
184-
channel: "${env.SLACK_CHANNEL}",
185-
color: color,
186-
message: """\
187-
*:rocket: Jenkins Build Notification :rocket:*
188-
189-
*Project:* `${projectName}`
190-
*Build Number:* `#${env.BUILD_NUMBER}`
191-
*Status:* ${jobResult == 'SUCCESS' ? ':white_check_mark: *Success*' : (jobResult == 'ABORTED' ? ':warning: *Aborted*' : ':x: *Failure*')}
192-
193-
:information_source: ${messageDetail}
194-
Triggered by: ${env.TRIGGERED_BY}
195-
:link: *Build URL:* <${jobUrl}|View Build Details>
196-
"""
153+
def notifySuccessful() {
154+
emailext (
155+
subject: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
156+
body: """SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':
157+
Check console output and connection attributes at ${env.BUILD_URL}""",
158+
159+
)
160+
}
161+
def notifyFailed() {
162+
emailext (
163+
subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
164+
body: """FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':
165+
Check console output at ${env.BUILD_URL}""",
166+
197167
)
198168
}

0 commit comments

Comments
 (0)