Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a jenkinsfile dropped into the root of my project and would like to pull in a groovy file for my pipeline and execute it. The only way that I've been able to get this to work is to create a separate project and use the fileLoader.fromGit command. I would like to do

def pipeline = load 'groovy-file-name.groovy'
pipeline.pipeline()
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.5k views
Welcome To Ask or Share your Answers For Others

1 Answer

If your Jenkinsfile and groovy file in one repository and Jenkinsfile is loaded from SCM you have to do:

Example.Groovy

def exampleMethod() {
    //do something
}

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

JenkinsFile

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...