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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

the.n...@gmail.com
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


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f5350044-b8b1-4e3e-b613-36bb9eade86ao%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

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

Devin Nusbaum
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.
 

On Aug 17, 2020, at 17:01, Randall Becker <[hidden email]> wrote:

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



--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f5350044-b8b1-4e3e-b613-36bb9eade86ao%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/C18CB9B5-3BD1-4658-B767-B259365D97B6%40cloudbees.com.
Reply | Threaded
Open this post in threaded view
|

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

the.n...@gmail.com
This was a new pipeline. I changed how the library was specified, using the library { lib } structure and that worked.

On Monday, 17 August 2020 17:26:48 UTC-4, Devin Nusbaum wrote:
This sounds like <a href="https://issues.jenkins-ci.org/browse/JENKINS-60245" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fissues.jenkins-ci.org%2Fbrowse%2FJENKINS-60245\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG0cbcYwjodTej8eDuKa48hoETRhQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fissues.jenkins-ci.org%2Fbrowse%2FJENKINS-60245\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG0cbcYwjodTej8eDuKa48hoETRhQ&#39;;return true;">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.
 

On Aug 17, 2020, at 17:01, Randall Becker <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="YNidym_ABgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">the....@...> wrote:

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



--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="YNidym_ABgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkins...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/f5350044-b8b1-4e3e-b613-36bb9eade86ao%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/f5350044-b8b1-4e3e-b613-36bb9eade86ao%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/f5350044-b8b1-4e3e-b613-36bb9eade86ao%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/f5350044-b8b1-4e3e-b613-36bb9eade86ao%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/2a941b57-aafa-4443-98a8-189f048d8738o%40googlegroups.com.