将日期设置为詹金斯管道中的工件目录名称

发布于 2025-01-17 09:12:10 字数 654 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聽兲甴掵 2025-01-24 09:12:10

为什么要加斜杠?
反斜杠()用于转义每种类型中的特殊字符,除了美元斜杠字符串,我们必须使用美元($)来转义。

在您的情况下,只需执行以下操作,

env.buildDateString="${new SimpleDateFormat('yyMMdd').format(new Date())}-${env.BUILD_NUMBER}"

{
 "pattern": "*abc*.zip",
 "target": "myrepo/application/${env.buildDateString}/artifacts/"
}

示例
输入图片此处描述

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}"

{
 "pattern": "*abc*.zip",
 "target": "myrepo/application/${env.buildDateString}/artifacts/"
}

sample
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文