詹金斯管道 - 主动选择反应性参数

发布于 2025-01-23 20:07:17 字数 1144 浏览 2 评论 0原文

以下脚本从目录中读取所有文件名,并将其显示给用户作为参数(无扩展),

import groovy.io.FileType

def list = []
def dir = new File("/var/lib/jenkins/workspace/grookins/folderx")

dir.eachFileRecurse (FileType.FILES) { file ->
list.add(file.getName().split("\\.",  2)[0])
}
return list

如果我将代码粘贴到UI中的Groovy脚本区域,则可以正常工作。

出于某种原因,从SCM运行脚本后,后斜切正在UI中变成一个简单的后斜线

,参数消失了

有人可以帮助我找到这种行为的原因吗?

The following script reads all file names from a directory and displays them to the user as parameters (without extension)

import groovy.io.FileType

def list = []
def dir = new File("/var/lib/jenkins/workspace/grookins/folderx")

dir.eachFileRecurse (FileType.FILES) { file ->
list.add(file.getName().split("\\.",  2)[0])
}
return list

It works fine if I paste the code into the Groovy Script area in the UI right here
enter image description here

enter image description here

Now if I paste the script into a Jenkinsfile,
enter image description here

for some reason, the backslashes are turning into a simple backslash in the UI after running the script from scm
enter image description here

and the parameters are gone
enter image description here

Can someone help me to find the reason for this behavior?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

风吹短裙飘 2025-01-30 20:07:17

通过尝试和错误,我发现在UI中,分裂函数中的正则态度与JenkinsFile中的解释不同。在Jenkinsfile中,需要4个后斜线才能逃脱UI中的点。

这就是Jenkinsfile中的条目:

list.add(file.getName().split("\\\\.",  2)[0])

By try and error i found out that the regex in the split function is interpreted differently in the UI than in the Jenkinsfile. In the Jenkinsfile 4 backslashes are required to escape the dot in the UI.

This is how the entry in the Jenkinsfile looks like:

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