将日期设置为詹金斯管道中的工件目录名称
我有一个 DSL 脚本,它创建一个推送到 jfrog 工件的管道。我想在artifactory 中创建一个目标目录,以当前日期作为目录名称。
import java.text.SimpleDateFormat
env.buildDateString="\${new SimpleDateFormat('yyMMdd').format(new Date())}-\${env.BUILD_NUMBER}"
...
...
//artifactory step
{
"pattern": "*abc*.zip",
"target": "myrepo/application/\${env.buildDateString}\\n/artifacts/"
}
上面的脚本给出了下面的代码片段,
{
"pattern": "*abc*.zip",
"target": "myrepo/application/${env.buildDateString}\n/artifacts/"
}
我希望使用日期创建目录。如何在artifactory的“目标”部分引用buildDateString,以便我得到这样的输出
"target": "myrepo/application/220328/artifacts/"
I have a DSL script that creates a pipeline to push to jfrog artifactory. I want to create a target directory in artifactory with current date as directory name.
import java.text.SimpleDateFormat
env.buildDateString="\${new SimpleDateFormat('yyMMdd').format(new Date())}-\${env.BUILD_NUMBER}"
...
...
//artifactory step
{
"pattern": "*abc*.zip",
"target": "myrepo/application/\${env.buildDateString}\\n/artifacts/"
}
The above script is giving the below snippet
{
"pattern": "*abc*.zip",
"target": "myrepo/application/${env.buildDateString}\n/artifacts/"
}
I want the directory to be created using the date. How to refer the buildDateString in "target" section of artifactory so I get output like this
"target": "myrepo/application/220328/artifacts/"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么要加斜杠?
反斜杠()用于转义每种类型中的特殊字符,除了美元斜杠字符串,我们必须使用美元($)来转义。
在您的情况下,只需执行以下操作,
env.buildDateString="${new SimpleDateFormat('yyMMdd').format(new Date())}-${env.BUILD_NUMBER}"
示例

Why the slashes?
backslash () is used to escape special characters in every type, except dollar-slashy string, where we must use dollar ($) to escape.
In your case just do as below,
env.buildDateString="${new SimpleDateFormat('yyMMdd').format(new Date())}-${env.BUILD_NUMBER}"
sample
