Skip to content

Instantly share code, notes, and snippets.

@samratshaw
Created September 27, 2018 10:22
Show Gist options
  • Save samratshaw/ab8e64d6573855835451757ed044f0c4 to your computer and use it in GitHub Desktop.
Save samratshaw/ab8e64d6573855835451757ed044f0c4 to your computer and use it in GitHub Desktop.
Medium: Jenkinsfile to accept build parameters (Sample shows sending email parameters)
node('linux') {
properties([[$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false],
parameters(
[
string(defaultValue: "", description: 'To', name: 'to'),
string(defaultValue: "", description: 'Cc', name: 'cc'),
string(defaultValue: "", description: 'Subject', name: 'subject'),
string(defaultValue: "", description: 'Body', name: 'body'),
string(defaultValue: "", description: 'From', name: 'from'),
]
)])
stage('Sending Email') {
if (to == "" || subject == "" || body == "") {
currentBuild.result = 'FAILURE'
sh "exit 1" // this fails the stage
}
mail(
to: "${to}",
cc: "${cc}",
subject: "${subject}",
body: "${body}",
from: "${from}",
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment