gpt4 book ai didi

jenkins - 如何加载 groovy 文件并执行它

转载 作者:行者123 更新时间:2023-12-01 19:40:09 24 4
gpt4 key购买 nike

我有一个 jenkinsfile 放入我的项目的根目录中,并且想为我的管道提取一个 groovy 文件并执行它。我能够让它工作的唯一方法是创建一个单独的项目并使用 fileLoader.fromGit 命令。我想做

def pipeline = load 'groovy-file-name.groovy'
pipeline.pipeline()

最佳答案

如果您的 Jenkinsfile 和 groovy 文件位于一个存储库中,并且 Jenkinsfile 是从 SCM 加载的,您必须执行以下操作:

示例.Groovy

def exampleMethod() {
//do something
}

def otherExampleMethod() {
//do something else
}
return this

Jenkins文件

node {
def rootDir = pwd()
def exampleModule = load "${rootDir}@script/Example.Groovy "
exampleModule.exampleMethod()
exampleModule.otherExampleMethod()
}

关于jenkins - 如何加载 groovy 文件并执行它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37800195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com