Below is the Jenkinsfile(scripted pipeline) code snippet to select a Git repo in stage view:
userInput = input(id: 'userInput',
message: 'Do you want to build?',
parameters: [
[$class: 'ChoiceParameterDefinition', choices: "repo_1\nNone", name: 'Env']
]
)
if (userInput.Env == "repo_1") {
print 'selected repo_1'
}
requests the user to select a repository and click Proceed
On clicking Proceed
button, jenkins throws error:
groovy.lang.MissingPropertyException: No such property: Env for class: java.lang.String
Manual build is only allowed for repo_1
Rest of the repositories suppose to be auto-triggered
Edit:
After making below changes,
node('worker_node'){
def userIdCause = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause')
def manualBuild = userIdCause.size()
stage("Auth-build") {
timeout(2) {
if (manualBuild) {
userInput = input(id: 'userInput',
message: 'Please select the repository',
parameters: [
[$class: 'ChoiceParameterDefinition', choices: "repo_1\nNone", name: 'Env']
]
)
if (userInput == "None") {
error('Error output')
}
repositoryName = 'repo_1'
}else if( !manualBuild && (repositoryName == 'repo_1')){
error('error output')
}
}
}
}
I do not get UI after clicking BuildNow
, I had to follow below process:
1) Why userInput.Env
gives missing property exception error?
2) input()
api takes a minute to render input wizard. Can we optimise?
No such property: Env for class: String
- i believe that input
function already returns the value of the single input. input
definition is quite simple in your case and does not contain any code (just constants) - nothing to optimize in it. Look for a time consumers in other places. Provide the "Choice Type" and "Referenced parameters" within Jenkins job to see the expected output. In your case Referenced parameters is "Env"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.