Jenkins Job DSL - 无法从文件加载参数
DSL 作业:
#!groovy
def file = readFileFromWorkspace('params.properties').trim()
job('app-adm') {
label("adm")
println("#" + file + "#")
parameters{
file
}
steps
{
shell(readFileFromWorkspace('script-adm.sh'))
}
}
job('app-tst-mt')
{
parameters
{
booleanParam('FLAG', true)
}
steps
{
shell(readFileFromWorkspace('script-tst-mt.sh'))
}
}
params.properties:
choiceParam('OPTION', ['option 1 (default)', 'option 2', 'option 3'])
我尝试过:
- 使用文件作为 Jenkins 的输入JobDSL
- 通过单个变量添加,例如
x=;和参数 { x }
- 不同的格式
什么都不起作用,通过作业内部的 println,我可以清楚地看到有一个我想放入参数中的字符串,但是这样做时它没有注册它,我也没有注册它没有得到任何参数。
DSL job:
#!groovy
def file = readFileFromWorkspace('params.properties').trim()
job('app-adm') {
label("adm")
println("#" + file + "#")
parameters{
file
}
steps
{
shell(readFileFromWorkspace('script-adm.sh'))
}
}
job('app-tst-mt')
{
parameters
{
booleanParam('FLAG', true)
}
steps
{
shell(readFileFromWorkspace('script-tst-mt.sh'))
}
}
params.properties:
choiceParam('OPTION', ['option 1 (default)', 'option 2', 'option 3'])
I've tried:
- Use files as input to Jenkins JobDSL
- adding through single variable like
x=<param> and parameteres { x }
- different formats
Nothing is working, through println inside job, I can clearly see that there is string that I want to put in parameters, but when doing so it dosen't register it and I don't get any params.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,答案是显而易见的,但如果有人遇到同样的问题,只需在 Jenkins 构建中的 DSL 工作之前先做一个 shell 工作即可。
在此 shell 作业中,您可以轻松修改工作区中的文件,因此将整个 dsl 作业(groovy 脚本)放在那里,只需用 sed 或 envsubst 替换部分文本即可。
Okey, the answer is stupidly obvious but if anybody has same problem just make a shell job previous to DSL job in Jenkins build.
In this shell job you can easily modify files in workspace, so place there a whole dsl job (groovy script), and just replace parts of text with sed or envsubst.