[JIRA] (JENKINS-43035) expression does not see imported classes

1 view
Skip to first unread message

gasterstaedt@ehealthexperts.de (JIRA)

unread,
Mar 22, 2017, 11:23:02 AM3/22/17
to jenkinsc...@googlegroups.com
Stefan Gasterstädt created an issue
 
Jenkins / Bug JENKINS-43035
expression does not see imported classes
Issue Type: Bug Bug
Assignee: Andrew Bayer
Components: pipeline-model-definition-plugin
Created: 2017/Mar/22 3:22 PM
Environment: Jenkins 2.50
Pipeline Model Definition PlugIn 1.1.1
Priority: Minor Minor
Reporter: Stefan Gasterstädt

The following Jenkinsfile snippet shows the fully quallified usage of an imported Type within an `expression` block. The whole Jenkinsfile can be executed without a failure.

```groovy

@Library('SomeManagedLibID') _
import some.package.MyType
[...]
stages {
  stage('Foobar') {
    when {
      expression {
        def xyz = new some.package.MyType()
        [...]
      }
```

Whereas the second snippet uses the short name (because it is imported) ...

```groovy

@Library('SomeManagedLibID') _
import some.package.MyType
[...]
stages {
  stage('Foobar') {
    when {
      expression {
        def xyz = new MyType()
        [...]
      }
```

... but in this case, the execution fails with a ProxyException:

```
Bitbucket] Build result notified
hudson.remoting.ProxyException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script2.groovy: 2: unable to resolve class MyType
@ line 2, column 10.
def cg = new MyType()
^

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.parse(CpsGroovyShell.java:55)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:584)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
at org.jenkinsci.plugins.workflow.cps.CpsScript.evaluate(CpsScript.java:167)
at org.jenkinsci.plugins.workflow.cps.CpsScript$evaluate.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:18)
at org.jenkinsci.plugins.pipeline.modeldefinition.when.impl.ExpressionConditionalScript.evaluate(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/when/impl/ExpressionConditionalScript.groovy:43)
at org.jenkinsci.plugins.pipeline.modeldefinition.when.impl.AllOfConditionalScript.evaluate(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/when/impl/AllOfConditionalScript.groovy:44)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateWhen(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:420)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:95)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withEnvBlock(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:223)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.withEnvBlock(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:222)
at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:94)
at __cps.transform__(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
at sun.reflect.GeneratedMethodAccessor330.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.LocalVariableBlock$LocalVariable.get(LocalVariableBlock.java:39)
at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
at com.cloudbees.groovy.cps.impl.LocalVariableBlock.evalLValue(LocalVariableBlock.java:28)
at com.cloudbees.groovy.cps.LValueBlock$BlockImpl.eval(LValueBlock.java:55)
at com.cloudbees.groovy.cps.LValueBlock.eval(LValueBlock.java:16)
at com.cloudbees.groovy.cps.Next.step(Next.java:74)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:165)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:328)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:80)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:240)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:228)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE
```
It looks like the `expression` does allow to execute groovy code but does not see the imported types.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

andrew.bayer@gmail.com (JIRA)

unread,
Mar 22, 2017, 11:55:01 AM3/22/17
to jenkinsc...@googlegroups.com
Andrew Bayer started work on Bug JENKINS-43035
 
Change By: Andrew Bayer
Status: Open In Progress

andrew.bayer@gmail.com (JIRA)

unread,
Mar 22, 2017, 12:18:01 PM3/22/17
to jenkinsc...@googlegroups.com
Andrew Bayer commented on Bug JENKINS-43035
 
Re: expression does not see imported classes

I've got a PR up for this at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/143, but I'm not sure it's the right solution yet. =)

andrew.bayer@gmail.com (JIRA)

unread,
Mar 22, 2017, 12:18:01 PM3/22/17
to jenkinsc...@googlegroups.com

gasterstaedt@ehealthexperts.de (JIRA)

unread,
Mar 23, 2017, 4:41:01 AM3/23/17
to jenkinsc...@googlegroups.com

gasterstaedt@ehealthexperts.de (JIRA)

unread,
Mar 23, 2017, 4:42:01 AM3/23/17
to jenkinsc...@googlegroups.com
Stefan Gasterstädt edited a comment on Bug JENKINS-43035
According to your groovy-unit-test [libraryObjectInWhenExpression.groovy ]( | https://github.com/abayer/pipeline-model-definition-plugin/blob/12a0443c5cece4a4a3b04f16d51a4f3f0bd3b2ca/pipeline-model-definition/src/test/resources/libraryObjectInWhenExpression.groovy ) ] , this looks exactly similar to my situation.


Thank you, that was a fast reaction.

andrew.bayer@gmail.com (JIRA)

unread,
Mar 23, 2017, 4:04:02 PM3/23/17
to jenkinsc...@googlegroups.com

New, better PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/144! This will require changing your Jenkinsfile to use the libraries directive, but I think it's the right long-term solution anyway. The original PR is now closed.

jglick@cloudbees.com (JIRA)

unread,
Mar 24, 2017, 2:11:01 PM3/24/17
to jenkinsc...@googlegroups.com

Maybe you should just get rid of scripted expressions. People who need to do fancy things like that can just use scripted Pipeline.

gasterstaedt@ehealthexperts.de (JIRA)

unread,
Mar 27, 2017, 5:03:02 AM3/27/17
to jenkinsc...@googlegroups.com
Stefan Gasterstädt edited a comment on Bug JENKINS-43035
As far as I understand, scripting is a valid option for declarative Jenkinsfiles. That is what
{code
:groovy }
steps {
  script { ... }
}
{code}
is made for. Similar, the {{expression}} block of {{when}} is made for script blocks.

Don't you think, that if scripting a when-conditionif is not a suitable option, a declarative Jenkinsfile should not offer
{code
:groovy }
when {
  expression { ... }
}
{code}
at all?

gasterstaedt@ehealthexperts.de (JIRA)

unread,
Mar 27, 2017, 5:03:02 AM3/27/17
to jenkinsc...@googlegroups.com

As far as I understand, scripting is a valid option for declarative Jenkinsfiles. That is what

Unable to find source-code formatter for language: groovy. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
steps {
  script { ... }
}

is made for. Similar, the expression block of when is made for script blocks.

Don't you think, that if scripting a when-conditionif is not a suitable option, a declarative Jenkinsfile should not offer

Unable to find source-code formatter for language: groovy. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
when {
  expression { ... }
}

at all?

gasterstaedt@ehealthexperts.de (JIRA)

unread,
Mar 27, 2017, 5:04:01 AM3/27/17
to jenkinsc...@googlegroups.com
Stefan Gasterstädt edited a comment on Bug JENKINS-43035
As far as I understand, scripting is a valid option for declarative Jenkinsfiles. That is what
{code}
steps {
  script { ... }
}
{code}

is made for. Similar, the {{expression}} block of {{when}} is made for script blocks.

Don't you think, that if scripting a when- conditionif condition is not a suitable option, a declarative Jenkinsfile should not offer
{code}
when {
  expression { ... }
}
{code}
at all?

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:24:46 PM10/22/19
to jenkinsc...@googlegroups.com
Liam Newman closed an issue as Fixed
 

Bulk closing resolved issues.

Change By: Liam Newman
Status: Resolved Closed
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages