-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Minor
-
Component/s: credentials-plugin, pipeline
-
Environment:Jenkins Version: 2.204.5
I am using DSL for the Jenkins pipeline as code. This particular piece of code runs fine .
pipeline {
agent {
label 'master'
}
stages {
stage('test script') {
steps {
script {
env.Environment_Name = input(id: 'Env', message: 'Select Environment',
parameters: [[$class: 'ChoiceParameterDefinition', choices: 'test-1\ntest-2\ntest-3', description: '', name: '']])
println ".... $Environment_Name"
def allCreds = sh(returnStdout: true,
script: "cat $JENKINS_HOME/jobs/$Environment_Name/config.xml | grep \"<id>\" | cut -d'>' -f2 | cut -d'<' -f1").trim().split('\n').join('\n')
println "----- $allCreds"
env.Cred_Name = input(id: 'Cred', message: 'Select Credential to Update',
parameters: [[$class: 'ChoiceParameterDefinition', choices: allCreds, description: '', name: '']])
println "----- $Cred_Name"
env.User_Name = input(id: 'User_Name', message: 'Enter Username',
parameters: [[$class: 'TextParameterDefinition', description: 'Username', name: 'User_Name']])
}
}
}
stage('print the variables') {
steps {
echo "${Environment_Name}"
echo "${User_Name}"
}
}
}
}
Â
But when I add environment block to this code it fails with the following exception java.lang.IndexOutOfBoundsException at hudson.MarkupText.rangeCheck(MarkupText.java:276)
pipeline {
agent {
label 'master'
}
environment {
JENKINS_CREDS = credentials('JENKINS_CREDS')
}
stages {
stage('test script') {
steps {
script {
env.Environment_Name = input(id: 'Env', message: 'Select Environment',
parameters: [[$class: 'ChoiceParameterDefinition', choices: 'test-1\ntest-2\ntest-3', description: '', name: '']])
println ".... $Environment_Name"
def allCreds = sh(returnStdout: true,
script: "cat $JENKINS_HOME/jobs/$Environment_Name/config.xml | grep \"<id>\" | cut -d'>' -f2 | cut -d'<' -f1").trim().split('\n').join('\n')
println "----- $allCreds"
env.Cred_Name = input(id: 'Cred', message: 'Select Credential to Update',
parameters: [[$class: 'ChoiceParameterDefinition', choices: allCreds, description: '', name: '']])
println "----- $Cred_Name"
env.User_Name = input(id: 'User_Name', message: 'Enter Username',
parameters: [[$class: 'TextParameterDefinition', description: 'Username', name: 'User_Name']])
}
}
}
stage('print the variables') {
steps {
echo "${Environment_Name}"
echo "${User_Name}"
echo "${JENKINS_CREDS_USR}"
}
}
}
}
Â
I have tested this code against the Jenkins version  2.222.1 and it runs without an error but fails when running in the version 2.204.5.