如何在Jenkins管道中比较日期

nhaq1z21  于 2023-06-05  发布在  Jenkins
关注(0)|答案(2)|浏览(179)

需要比较格式为- yyyy-mm-dd HH:MM:SS的日期
我尝试过使用Date.Parse,但不允许使用Groovy沙箱,我需要在脚本管道中进行比较。

No such static method found: staticMethod java.util.Date parse java.lang.String java.lang.String. Administrators can decide whether to approve or reject this signature.
[Pipeline] End of Pipeline
[Office365connector] No webhooks to notify
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such static method found: staticMethod java.util.Date parse java.lang.String java.lang.String
    at
nwlqm0z1

nwlqm0z11#

如果你想有一个现成的代码,请找到下面的代码:

import java.text.SimpleDateFormat
import java.util.Date

Date parseStringToDate(String createdDateStr) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd HH:MM:SS")
    dateFormat.timeZone = TimeZone.getTimeZone("UTC")
    Date parsedDate = dateFormat.parse(createdDateStr)
    return parsedDate
}
4ioopgfo

4ioopgfo2#

您可以选择need to approve the Date.parse,或者使用允许的沙箱

new SimpleDateFormat(format).parse(input)

相关问题