欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

如何在Jenkins Pipeline中获取当前时间?

最编程 2024-08-08 17:27:07
...

在 Jenkins Pipeline 中,你可以使用 currentTime 函数来获取当前时间。该函数返回值为当前时间的毫秒数。

语法为:

currentTime()

如果你需要格式化时间,可以将其转换为 java.util.Date 类型,然后使用 SimpleDateFormat 格式化。

示例:

def current_time = new Date(currentTime())
def simple_date_format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
def formatted_time = simple_date_format.format(current_time)

echo "Current time is: ${formatted_time}"

在上面的例子中,我们使用了 yyyy-MM-dd HH:mm:ss 格式,你可以根据需要更改格式。