如何从 Jenkins 2.0 管道脚本中读取属性文件 [英] How to read properties file from Jenkins 2.0 pipeline script
问题描述
我正在尝试编写一个管道脚本以与 Jenkins 2.0 一起使用来复制我们现有的构建.这个原始构建使用 envInject 插件来读取 Java 属性文件,但我无法从管道 Groovy 脚本中看到如何执行此操作.我用谷歌搜索并找到以下内容,但它不起作用(FileNotFoundException):
I am attempting to write a pipeline script to use with Jenkins 2.0 to replicate our existing build. This original build used the envInject plugin to read a Java properties file, but I can't see how to do this from the pipeline Groovy script. I have Googled and found the following, but it doesn't work (FileNotFoundException):
Properties props = new Properties()
File propsFile = new File('./Builder/project.properties')
props.load(propsFile.newDataInputStream())
谢谢!
推荐答案
我昨天和今天刚和这个打过架.我希望更容易找到它的可用性.
I just fought with this yesterday and today. I wish the availability of this was easier to find.
抓住'Pipeline Utility Steps' 插件.
使用 readProperties 步骤.
Use the readProperties step.
def props = readProperties file: 'dir/my.properties'
一句警告 - 我希望属性文件中的布尔值被视为字符串.
One word of warning - what I expected to be booleans in the properties files were treated as strings.
这篇关于如何从 Jenkins 2.0 管道脚本中读取属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!