jenkins - 无法在 groovy DSL 中拆分字符串并且没有多行
问题描述
我正在尝试在 Jenkins 的 groovy DSL 中拆分 URL http://localhost:8081/artifactory/api/storage/myrepo/sub1/file.zip。它是一个单行字符串。但是下面的代码不起作用
String[] arr= string_var.split('/');
String[] arr=string_var.split('\\/');
它不会拆分它并在 arr[0] 中返回自身。我不确定这是否是一个错误。请让我知道 groovy 中是否有任何其他方式可以从 URL 字符串中获取“sub1”。
解决方案
您确定您正确地执行 DSL 脚本吗?由于 groovy 代码看起来没问题。尝试跳过声明类型
def url_str = 'http://localhost:8081/artifactory/api/storage/myrepo/sub1/file.zip'
def sub = url_str.split('/')[-2]
println(sub)
在一行中:
println('http://localhost:8081/artifactory/api/storage/myrepo/sub1/file.zip'.split('/')[-2])
没有拆分,索引:
def url_str = 'http://localhost:8081/artifactory/api/storage/myrepo/sub1/file.zip'
int[] indexes = url_str.findIndexValues {it == "/"}
println url_str.substring(indexes[-2] + 1, indexes[-1])
推荐阅读
- iis - 使用符号链接访问 wwwroot 之外的文件夹
- arduino - 无法使用 SPIFFS
- node.js - Mailgun.js 是否提供发送模板的可能性?
- netlogo - NetLogo 中的 KOSKK 网络模型
- c# - 在 Xamarin 应用程序中,如何编写启动新活动的方法?
- oracle - Oracle XQuery 删除、插入、更新
- xml - 如何使用 symfony 3.4 将 xml soap 请求转换为 DOMDocument
- java - 使用 Spring-boot 和 java nio 包下载较大的(视频)文件时,仅下载部分文件
- javascript - Vue &
- python-3.x - 查找数据框中所有行的情绪分析,而不仅仅是一个