You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为readProperties读取文件添加过滤规则?忽略下划线开头的键

过滤Properties文件中下划线开头的键

针对你的需求,只需在收集参数前先过滤掉键以下划线_开头的条目即可,修改后的代码如下:

props = readProperties file: "parameter_file"
// 先过滤掉键以_开头的属性
fileParams = props.findAll { !it.key.startsWith('_') }.collect { string(name: it.key, value: it.value) }
build job: "jobName", parameters: fileParams

代码说明

  • props.findAll { !it.key.startsWith('_') }:遍历读取到的所有属性,只保留键不以下划线开头的条目,自动排除_project、_branch这类符合过滤规则的键。
  • 后续的collect操作仅针对过滤后的属性,生成Jenkins构建所需的字符串参数列表。

内容的提问来源于stack exchange,提问作者rodee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 05:03:27