简体   繁体   中英

Call utility function from a utility function in a Jenkins Pipeline Shared Library

I am following the example under Accessing steps . In src/org/foo/Zot.groovy I would like to call a utility function defined in eg src/org/foo/Bar.groovy . How to do that?

I tried several things without success, eg:

// src/org/foo/Zot.groovy
package org.foo;

def bar = new org.foo.Bar()

def checkOutFrom(repo) {
  bar.someFunction()
  git url: "git@github.com:jenkinsci/${repo}"
}

In this case Jenkins hangs on loading the global library. I also tried to import the file.

There have been reproduction of a similar, and probably related problem here: https://issues.jenkins-ci.org/browse/JENKINS-31484

I reproduced a similar situation using the Global CPS Library. The executor stack trace shows that the thread gets locked in InvokerInvocationException, like in the link provided.

I was able to workaround my small reproduce case by adding the @NonCPS annotation to all the called methods down the line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM