Trying to use Global Shared Groovy in Pipelines - ERROR: Could not find any definition of libraries [mylib]

1,464 views
Skip to first unread message

Randall Becker

unread,
Aug 17, 2020, 5:01:37 PM8/17/20
to Jenkins Users
I'm having some difficulty with global shared groovy libraries in pipelines (Jenkins 2.242, with Pipeline:Groovy Shared Libraries 2.16) and could use a swift kick in the proper direction.

I've configured a local bare git repository using it's path in the System Configuration, which correctly reports the commit associated with the HEAD of master. Since this is local, there are no credentials involved.

The groovy script is loaded in my pipeline (not a Jenkinsfile, just a simple project), as follows - from a file outside the workspace, which is not yet populated at the load step:

        stage('load') {
            steps {
                script {
                    modules.first = load pwd()+'/../../OtherJob/workspace/publisher.groovy'
                }
            }
        }

The load works and I can execute simple things, but when trying to reference the library I get the error that
ERROR: Could not find any definition of libraries [mylib],

The first line of the publisher.groovy script is:
@Library('mylib') _

And the exception thrown is below (there is more, obviously). Nothing in the jenkins log, this is from the build console

org.jenkinsci.plugins.workflow.cps.CpsCompilationErrorsException: startup failed:
Script1.groovy: Loading libraries failed

1 error

	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
...

I really want to share code (not variables) as I have about 30 pipelines that need my groovy classes. Obviously I'm doing something wrong, but the diagnostics are not providing a nice hint to help me out with resolving this. Any suggestions?

Thanks in advance,
Randall


Devin Nusbaum

unread,
Aug 17, 2020, 5:26:48 PM8/17/20
to Jenkins Users
This sounds like JENKINS-60245. There is a proposed fix, but I have not had time to review it. 

Is this something you had working previously, and it was broken by an update or something, or are you just trying it for the first time?

You might be able to use the `library` step instead of the `@Library` annotation as a workaround for now.
 

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f5350044-b8b1-4e3e-b613-36bb9eade86ao%40googlegroups.com.

Randall Becker

unread,
Aug 18, 2020, 4:22:59 PM8/18/20
to Jenkins Users
This was a new pipeline. I changed how the library was specified, using the library { lib } structure and that worked.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages