简体   繁体   English

无法从 jenkins 的属性文件中读取参数

[英]Not able to read parameters from properties file in jenkins

Here is what I am trying to achieve.这是我想要实现的目标。 - I have two 'Choice Parameters' in my Jenkins job. - 我的 Jenkins 作业中有两个“选择参数”。 The values of the first Choice Parameter are hard coded.第一个选择参数的值是硬编码的。 The second choice list should be populated based on the first choice list selection.应根据第一选择列表选择填充第二选择列表。 I have one properties file saved in Jenkins, which has key-value pairs.我在 Jenkins 中保存了一个属性文件,其中包含键值对。 The values in first choice list and the Keys in the file are same.首选列表中的值和文件中的 Keys 相同。 On selecting a value in first choice list i want a code to read the properties file and populate the second choice parameter with the values from file corresponding to that key.在第一选择列表中选择一个值时,我想要一个代码来读取属性文件并使用与该键对应的文件中的值填充第二选择参数。 For second choice list i am trying with 'Active Choice Reactive Parameter', Referenced parameters= first_choice and below groovy script.对于第二选择列表,我正在尝试使用“Active Choice Reactive Parameter”,引用参数= first_choice 并低于 groovy 脚本。 But this is not returning any values.但这不会返回任何值。 Please help!请帮忙!

 def firstChoice = [first_choice]
 Properties props = new Properties()
 def stream = new FileInputStream('C:/Jenkins/books.properties')
 try{
     props.load(stream)
    }
    catch (Exception ex){
     println "Exception"
    }
    finally {
      stream.close()
    }
 def values = props.getProperty(firstChoice).split(",")
 return values

Are the parameters defined in your job? 您的工作中是否定义了参数? if you're trying to inject parameters that are not defined in the job you need to either define them or add exception in Jenkins when you're loading the master service. 如果您尝试注入未在作业中定义的参数,则需要在加载主服务时定义它们或在Jenkins中添加例外。

More reading: https://wiki.jenkins-ci.org/display/JENKINS/Plugins+affected+by+fix+for+SECURITY-170 更多阅读: https//wiki.jenkins-ci.org/display/JENKINS/Plugins+affected+by+fix+for+SECURITY-170

Follow this answer and use active choices parameter.按照这个答案并使用主动选择参数。 This will help you achieve what you want to https://stackoverflow.com/a/73742809/4781673这将帮助您实现您想要的https://stackoverflow.com/a/73742809/4781673

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM