詹金斯管道 - 主动选择反应性参数
以下脚本从目录中读取所有文件名,并将其显示给用户作为参数(无扩展),
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
Now if I paste the script into a Jenkinsfile,
for some reason, the backslashes are turning into a simple backslash in the UI after running the script from scm
Can someone help me to find the reason for this behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过尝试和错误,我发现在UI中,分裂函数中的正则态度与JenkinsFile中的解释不同。在Jenkinsfile中,需要4个后斜线才能逃脱UI中的点。
这就是Jenkinsfile中的条目:
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: