且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在詹金斯管道上提取部分字符串

更新时间:2023-02-21 18:51:35

在这种情况下,似乎在 String 上使用一些 Groovy/Java 方法可以提取部分.

In this case, it looks like using a few Groovy/Java methods on the String can extract the parts.

final beforeColon = url.substring(0, url.indexOf(':'))  // git@github.com
final afterLastSlash = url.substring(url.lastIndexOf('/') + 1, url.length()) // project/access-server-pd.git

这使用了几种不同的方法:

This uses a few different methods:

您确实需要小心您在管道中使用的代码.如果它是沙盒的,它将在一个受保护的域中运行,每个调用都经过安全检查.例如,脚本安全中的" rel="noreferrer">白名单插件 将上面使用的所有调用列入白名单(例如,方法 java.lang.String lastIndexOf java.lang.String).

You do need to be careful about the code you use in your pipeline. If it is sandboxed it will run in a protected domain where every invocation is security checked. For example, the whitelist in the Script Security Plugin whitelists all of the calls used above (for example, method java.lang.String lastIndexOf java.lang.String).

在您的管道代码中执行 String 操作是完全合理的,因为您可能会根据它做出决策并更改您的编排.

Performing String manipulation in your pipeline code is perfectly reasonable as you might make decisions and change your orchestration based on it.