【发布时间】:2019-01-02 03:10:40
【问题描述】:
我有一个有点独特的设置,我需要能够动态加载位于我正在构建的 src 之外的 Jenkinsfile。 Jenkinsfiles 本身通常调用 node() 然后是一些构建步骤。这会导致多个执行程序不必要地被吃掉,因为我需要已经调用 node() 才能使用加载步骤来运行 Jenkinsfile,或者如果我将 Jenkinsfile 作为字符串读取并执行它,则执行 groovy。
我今天在工作 UI 中的内容:
@Library(value='myGlobalLib@head', changelog=fase) _
node{
load "${JENKINSFILES_ROOT}/${PROJECT_NAME}/Jenkinsfile"
}
加载的 Jenkinsfile 通常也会调用 node()。例如:
node('agent-type-foo'){
someBuildFlavor{
buildProperty = "some value unique to this build"
someConfig = ["VALUE1", "VALUE2", "VALUE3"]
runTestTarget = true
}
}
这会导致在管道运行期间消耗 2 个执行器。理想情况下,我在没有先调用 node() 的情况下加载 Jenkinsfiles,但是每当我尝试时,我都会收到一条错误消息:
"Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node"
有没有办法在没有 hudson.FilePath 上下文的情况下加载 Jenkinsfile 或执行 groovy?我似乎在文档中找不到任何东西。我正准备对 Jenkinsfile 进行预处理,以删除它们对 node() 的初始调用,并使用 Jenkinsfile 使用的值调用 node(),然后加载文件的其余部分,但是,这有点太对我来说很脆弱。
【问题讨论】: