|
// src/com/example/Helper.groovy |
|
#!/usr/bin/env groovy |
|
package com.example |
|
|
|
class Helper implements Serializable { |
|
def context |
|
Helper(context) { |
|
this.context = context |
|
} |
|
|
|
def getUserInput(script) { |
|
// Following didnt' work. |
|
def ANSWER = context.input(message: 'Please provide parameters', ok: 'Next', |
|
parameters: context.choice(name: 'ANSWER', choices: ['yes', 'no'].join('\n'), description: 'Select Answer?')) |
|
|
|
// Tried following, this also didn't work |
|
//def ANSWER = input(message: 'Please provide parameters', ok: 'Next', |
|
// parameters: choice(name: 'ANSWER', choices: ['yes', 'no'].join('\n'), description: 'Select Answer?')) |
|
|
|
// Tried following, this also didn't work |
|
//def ANSWER = script.input(message: 'Please provide parameters', ok: 'Next', |
|
// parameters: script.choice(name: 'ANSWER', choices: ['yes', 'no'].join('\n'), description: 'Select Answer?')) |
|
|
|
return ANSWER |
|
} |
|
} |
|
|
|
// Used the above class as in the Jenkinsfile |
|
import com.example |
|
def helper = new Helper(this); |
|
pipeline { |
|
stages { |
|
stage("UserInputs") { |
|
steps { |
|
script { |
|
env.ANSWER=helper.getAnswer(env) |
|
} |
|
} |
|
} |
|
} |
|
} |
|
// --------------- Helper.groovy ends ----------- |
|
|
|
// var/getAnswer.groovy |
|
|
|
def call() { |
|
def ANSWER = input(message: 'Please provide parameters', ok: 'Next', |
|
parameters: choice(name: 'ANSWER', choices: ['yes', 'no'].join('\n'), description: 'Select Answer?')) |
|
return ANSWER |
|
} |
|
|
|
// Used it as below in Jenkins file, this also didn't work |
|
|
|
pipeline { |
|
stages { |
|
stage("UserInputs") { |
|
steps { |
|
script { |
|
env.ANSWER = getAnswer() |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
// ------ getAnswer.groovyy ends here ----------- |