【发布时间】:2020-07-22 09:16:00
【问题描述】:
我在/src/ru/foo/bar/Const.groovy 中有一些只有常量而没有任何方法的类
package ru.foo.bar
class Const {
public static final String BITBUCKET_LOGIN = "DEV_LOGIN"
public static final String BITBUCKET_PASS = "DEV_PASS"
{
在 Jenkins 管道中,我这样使用它:
import ru.foo.bar.Const
pipeline {
stages {
stage {
script {
println("${Const.BITBUCKET_LOGIN}")
doSomeThingWith(PASS: "${Const.BITBUCKET_PASS}")
}
}
}
}
一切正常!
现在我需要为不同的环境制作不同的文件并在管道中动态加载它,但这样管道中的其他内容就不会发生任何变化。
我尝试评论//import ru.foo.bar.Const
并将类似的东西添加到管道中
sh 'cp environments/${Stand}/Const.groovy jenkins/Const.groovy'
def Const = load 'jenkins/Const.groovy'
println("${Const.BITBUCKET_LOGIN}")
doSomeThingWith(PASS: "${Const.BITBUCKET_PASS}")
我也试过了
load 'jenkins/Const.groovy'
但这并不像谷歌的其他想法那样奏效。
如何在管道中正确加载我的类,以便我可以访问像 ${Const.SOMEVARIABLE} 这样的常量?
【问题讨论】:
标签: class jenkins groovy import load