I am newbie to jenkins pipeline scripting and i am just trying to concatenate date to string getting below No Such Property exception. Dont know where am doing wrong. Could some one please help me to resolve this
def generateRandomText(){
def temp = ""
try{
Date date = new Date()
String datePart = date.format("ddHHmmssSSS")
temp = "abcde" + datepart
echo "printing ... $temp"
return temp
}
catch(theError){
echo "Error getting while generating random text: {$theError}"
}
return temp
}
MissingPropertyException
means the variable wasn't declared.
There were some errors in your code:
You used echo
, which doesn't exist in Groovy. Use one of the print
functions instead. On the code below I used println
The datePart
variable was mispelled
Here's your code fixed:
def generateRandomText(){
def temp = ""
try{
Date date = new Date()
String datePart = date.format("ddHHmmssSSS")
temp = "abcde" + datePart
println "printing ... $temp"
return temp
}
catch(theError){
println "Error getting while generating random text: {$theError}"
}
return temp
}
generateRandomText()
Output on groovyConsole:
printing ... abcde21195603124
Result: abcde21195603124