Using @grab to fetch SNAPSHOT jar in groovy sometimes can't be recoganized correctly if updating the SNAPSHOT

68 views
Skip to first unread message

pan

unread,
Oct 8, 2018, 10:34:58 AM10/8/18
to Jenkins Users
Hi,

I got an issue when using @grab.
We are developing a jar and pipeline script to do the CI. We modify some java code, deploy onto our internal Nexus server, use @grab in groovy to fetch it to call the function.
During developing, we found when we modify some code, deploy a new SNAPSHOT version with the same version number of jar, sometimes the pipeline script is not working.

For example:

@GrabResolver(name='Internal Nexus Snapshot', root='https://internal.nexus.com/')
@Grab('some-package:some-artifact:0.0.1-SNAPSHOT')
import some.Utils
println new Utils()

It works well, but if I deploy a new version to Nexus, it might fail, unless I restart the Jenkins, then it will work again.

error message:
Running in Durability level: MAX_SURVIVABILITY
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 1: unable to resolve class some.Utils
 @ line 1, column 1.
   @GrabResolver(name='Internal Nexus Snapshot', root='https://internal.nexus.com/')
   ^

1 error

	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
	at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:958)
	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605)
	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:554)
	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)
	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:131)
	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:125)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:560)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:521)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:290)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:421)
Finished: FAILURE


I think it might be some cache in Jenkins, because restart Jenkins will fix it. But I can't find it.
Does anyone have any clue about this?
Thank you very much.


pan

unread,
Nov 3, 2018, 1:13:41 AM11/3/18
to Jenkins Users
Updates:

It might not be a good idea to use @grab in Jenkins pipeline script.

We also found an issue about this: https://issues.jenkins-ci.org/browse/JENKINS-48974, this will cause the parallel jobs which @grab the same direct/indirect dependencies failed.

It seems related to the groovy/ivy issue: https://issues.apache.org/jira/browse/GROOVY-7407. And it’s not fixed yet…

We also consider the way of @Library, but in the groovy lib, we still need @grab 3rd party lib, which is the same situation.

Anyway, we refactor the dependencies into a service and call rest api from the pipeline script, it seems working.

BR
Wei 

在 2018年10月8日星期一 UTC+2下午4:34:58,pan写道:
Reply all
Reply to author
Forward
0 new messages