0

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

} 
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
reachit
  • 53
  • 1
  • 3
  • 11

1 Answers1

2

MissingPropertyException means the variable wasn't declared.

There were some errors in your code:

  1. You used echo, which doesn't exist in Groovy. Use one of the print functions instead. On the code below I used println

  2. 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

See Groovy's documentation.

Maicon Mauricio
  • 2,052
  • 1
  • 13
  • 29