Search code examples
groovyparametersjenkins-pipelinejenkins-groovy

Groovy script is not working in Jenkins Active choice parameter


I am working a groovy script which is working perfectly on the Jenkins Scriptler but when I tried to run the same script from active choice parameter, it is not returning any values.

Could someone help me on this?

import java.time.format.DateTimeFormatter
exception_file = "test/10-01-2023/test"
String ex_date = exception_file.split('/')[1].toString()
println ex_date
cDate = java.time.LocalDate.now()
currentDate = cDate.format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
expiry_date = Date.parse("dd-MM-yyyy", ex_date)
return expiry_date

But in parameters it is empty. AM i missing something?


Solution

  • I've reproduced the problem using your code. The only thing you are missing is the correct return type. It must be either java.util.List, Array, or java.util.Map.

    In the following I'm returning an array.

    import java.time.format.DateTimeFormatter
    exception_file = "test/10-01-2023/test"
    String ex_date = exception_file.split('/')[1].toString()
    println ex_date
    cDate = java.time.LocalDate.now()
    currentDate = cDate.format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
    expiry_date = Date.parse("dd-MM-yyyy", ex_date)
    return [ expiry_date ]
    

    This renders like:

    ActiveChoice parameter