Skip to content

Instantly share code, notes, and snippets.

@rkalit
Last active July 19, 2019 04:11
Show Gist options
  • Select an option

  • Save rkalit/5718a957690bd1a19978ea5f72dc89c8 to your computer and use it in GitHub Desktop.

Select an option

Save rkalit/5718a957690bd1a19978ea5f72dc89c8 to your computer and use it in GitHub Desktop.
Jenkinsfile Test to ask input from user
def didTimeout = false
def abortStatus = false
pipeline {
agent any
stages {
stage ('Deploy Application') {
steps {
script {
try {
echo "Assume the Deploy feature/alpha is Success"
try {
timeout(time: 5, unit: 'MINUTES') {
env.userChoice = input message: 'Do you want to Deploy?',
parameters: [choice(name: 'Versioning Service', choices: 'no\nyes', description: 'Choose "yes" if you want to deploy this build')]
}
if (userChoice == 'no') {
echo "User refuse to release"
}
} catch (Exception err){
def user = err.getCauses()[0].getUser()
if ('SYSTEM' == user.toString()) {
didTimeout = true
} else {
echo "Process abort by: ${user}"
}
}
} catch (Exception err) {
echo "if Fail it will send report"
}
}
}
}
stage ('Deploy Release') {
when {
environment name: 'userChoice', value: 'yes'
}
steps {
script {
try {
timeout(time: 5, unit: 'MINUTES') {
versionName = input (
id: 'version', message: 'Input version name', parameters: [
[$class: 'TextParameterDefinition', description: 'Whatever you type here will be your version', name: 'Version']
]
)
}
} catch (Exception err) {
def user = err.getCauses()[0].getUser()
if ('SYSTEM' == user.toString()) {
didTimeout = true
} else {
echo "Job Aborted by: ${user}"
}
}
echo "This VersionName will be: ${versionName}"
}
}
}
}
environment {
serviceName = "serName"
releaseName = "relName"
commitId = "commId"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment