Skip to content

Instantly share code, notes, and snippets.

@eliskvitka
Created September 2, 2021 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliskvitka/5d85b63df7ed4a38629c6ca9fd4b141f to your computer and use it in GitHub Desktop.
Save eliskvitka/5d85b63df7ed4a38629c6ca9fd4b141f to your computer and use it in GitHub Desktop.
[Jenkins] Jenkins Shared Library example usage from scripted pipeline
#!/usr/bin/env groovy
@Library('devopslib')
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
import spv.devops.*
// Create shared library instance with jenkins `steps` object
def utils = new Utils(this)
node {
try {
stage("Notify started build") {
withCredentials([string(credentialsId: <token_id>, variable: 'TOKEN')]) {
// Using function from shared library
utils.sendToTelegram(TOKEN, env.NOTIFY_CHAT_ID, "Build started" as String)
}
}
stage("Git checkout") {
git branch: 'master',
credentialsId: <token_id>,
url: <url>
}
stage("Docker Build") {
sh "docker build --file .deploy/Dockerfile ."
}
}
catch (FlowInterruptedException exc) {
currentBuild.result = 'ABORTED'
}
catch (Exception exc) {
println "Failed"
println(exc as String)
currentBuild.result = 'FAILURE'
}
finally {
cleanWs()
withCredentials([string(credentialsId: <token_id>, variable: 'TOKEN')]) {
utils.sendToTelegram(TOKEN, env.NOTIFY_CHAT_ID, "Build finished" as String)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment