I am trying to send schedule for today's deployment so for that I am trying to comparing the dates and if date matches then it should "YES" to stringbuilder and if it doesn't match then it should send "No" to stringbuilder respectively. For that I have written groovy script for Jenkins likewise-
echo "FIT2 Deployment started"
if(runConfig.FIT2Deploy){
FIT2Deploy = sb.append(padToLength('FIT2', 15)).append('|')
}
}
stage('Log Intent') {
echo runConfig.stringify()
}
String makeMarkFor(boolean bool) {
return (bool ? "Yes" : "No")
}
class RunConfig implements Serializable {
String padToLength(String initialValue, int length) {
String tmpVal = initialValue
while (tmpVal.length() < length) {
tmpVal = tmpVal + " "
}
return tmpVal
}
String centerPadToLength(String initialValue, int length) {
String tmpVal = initialValue
boolean atFront = false
while (tmpVal.length() < length) {
if (atFront) {
tmpVal = " " + tmpVal
} else {
tmpVal = tmpVal + " "
}
atFront = !atFront
}
}
String stringify() {
def sb = StringBuilder.newInstance()
sb.append('The following is the schedule for today ').append('|')
sb.append('\n================================\n')
sb.append(padToLength('Environment', 15)).append('|')
sb.append(padToLength(' Deploy', 8))
sb.append('\n--------------------------------\n')
//sb.append(padToLength('FIT2', 15)).append('|')
sb.append(centerPadToLength(makeMarkFor(FIT2Deploy), 8))
sb.toString()
}
}
But It is not working can someone please help me? I am expecting output-
You can change padToLength('Environment', 15)
to 'Environment'.padRight(15)
and get rid of your padToLength
method
You can change centerPadToLength(makeMarkFor(FIT2Deploy), 8)
to makeMarkFor(FIT2Deploy).center(8)
and get rid of your centerPadToLength
method
And then looking at your code, you probably want makeMarkFor(runConfig.FIT2Deploy).center(8)
, but it's hard to tell as the logic is a bit complex with the same variable names used in different context
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.