Created
September 2, 2021 07:30
-
-
Save eliskvitka/5d85b63df7ed4a38629c6ca9fd4b141f to your computer and use it in GitHub Desktop.
[Jenkins] Jenkins Shared Library example usage from scripted pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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