[JIRA] (JENKINS-58643) CPS Mismatches on cpsScript.InvokeMethod

0 views
Skip to first unread message

robin@jfrog.com (JIRA)

unread,
Jul 24, 2019, 11:46:02 AM7/24/19
to jenkinsc...@googlegroups.com
Robi Nino created an issue
 
Jenkins / Improvement JENKINS-58643
CPS Mismatches on cpsScript.InvokeMethod
Issue Type: Improvement Improvement
Assignee: Unassigned
Components: workflow-cps-plugin
Created: 2019-07-24 15:45
Environment: Jenkins 2.187, Pipeline:Groovy plugin 2.7.2, Artifactory Plugin 2.16.2
Priority: Minor Minor
Reporter: Robi Nino

Hello,

Following the introduction of a new warning log message in version 2.7.1 of the Pipeline:Groovy plugin, we are now receiving types of the following warning in builds using the Artifactory Plugin:

expected to call org.jfrog.hudson.pipeline.common.types.ArtifactoryServer.upload but wound up catching artifactoryUpload

The pipeline API supported by the Artifactory plugin creates objects, on which methods can be invoked.
For example:

def server = Artifactory.server 'my-server'
server.upload ...

Notice that the 'server' object allows executing the 'artifactoryUpload' step.
This OOP style is very convenient and allows reusing code and configuration. This approach received very positive feedbacks since it was introduced.
Currently however, this is achieved by having the 'server' instance store the CpsScript, so that it can be used to invoke the step (by using 'cpsScript.invokeMethod').

The Artifactory pipeline API is available for a few years already and has become extremely popular.
We would appreciate your advice on how to change the plugin in a way that will both satisfy the CPS guidelines without breaking its current functionality and structure.

Alternatively, the usage of cpsScript.invokeMethod could be added as an exception to the cps mismatch report, similar to the proposed addition in this PR.

Thank you

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

steventerrana@gmail.com (JIRA)

unread,
Jul 25, 2019, 11:48:02 AM7/25/19
to jenkinsc...@googlegroups.com
Steven Terrana commented on Improvement JENKINS-58643
 
Re: CPS Mismatches on cpsScript.InvokeMethod

For what it's worth, the  Templating Engine Plugin  had almost the exact same issue where objects created and injected into the binding were throwing CPS Mismatch warnings.

we're refactoring anything placed in the binding that's going to be invoking methods to be CPS transformed before being placed injected.  

After doing this - the only CpsMismatch warnings we got were around metaprogramming examples such as using InvokerHelper to invoke methods, or by taking advantage of groovy's methodMissing functionality.

those use cases are being addressed in https://github.com/cloudbees/groovy-cps/pull/99

eyalb@jfrog.com (JIRA)

unread,
Aug 1, 2019, 7:46:02 AM8/1/19
to jenkinsc...@googlegroups.com

Thanks you Steven Terrana - we're not sure we can implement a similar solution in the Artifactory Plugin.

Devin Nusbaum - In our case, the method name used in the pipeline script (for example, "upload"), is different from the name returned by DescriptorImpl.getFunctionName() ("artifactoryUpload").  Can you please recommend a solution?

Thanks

dnusbaum@cloudbees.com (JIRA)

unread,
Aug 1, 2019, 10:03:02 AM8/1/19
to jenkinsc...@googlegroups.com

dnusbaum@cloudbees.com (JIRA)

unread,
Aug 1, 2019, 10:03:03 AM8/1/19
to jenkinsc...@googlegroups.com

Eyal Ben Moshe Hmm, looks like your code is rather unique, you directly call CpsScript.invokeMethod inside of ArtifactoryServer.upload. This kind of metaprogramming is opaque to the CPS method mismatch detector because ArtifactoryServer.upload is in a Plugin rather than directly in a shared library or the Pipeline itself, so what we did for Steven Terrana's case doesn't apply here.

CC Jesse Glick, any ideas on a fix or workaround? The only thing I can think of would be to ignore mismatch warnings in workflow-cps whenever the receiver is a plugin using something like this:

diff --git a/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsVmExecutorService.java b/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsVmExecutorService.java
index 7034810e..e96757cb 100644
--- a/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsVmExecutorService.java
+++ b/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsVmExecutorService.java
@@ -12,4 +12,5 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.annotation.CheckForNull;
+import jenkins.model.Jenkins;
 import jenkins.util.InterceptingExecutorService;
 
@@ -113,4 +114,9 @@ class CpsVmExecutorService extends InterceptingExecutorService {
 
     private void handleMismatch(Object expectedReceiver, String expectedMethodName, Object actualReceiver, String actualMethodName) {
+        Class receiverClass = expectedReceiver.getClass();
+        if (Jenkins.get().getPluginManager().whichPlugin(receiverClass) != null) {
+            // Plugin code is opaque to the mismatch detector.
+            return;
+        }
         String mismatchMessage = mismatchMessage(className(expectedReceiver), expectedMethodName, className(actualReceiver), actualMethodName);
         if (FAIL_ON_MISMATCH) {

I haven't tested that to see if it even works, and I think that might also mask real problems in DSLs like pipeline-model-definition and docker-workflow, so it doesn't seem like a great solution.

dnusbaum@cloudbees.com (JIRA)

unread,
Aug 1, 2019, 10:03:03 AM8/1/19
to jenkinsc...@googlegroups.com
Devin Nusbaum updated an issue
 
Jenkins / Bug JENKINS-58643
CPS Mismatches on cpsScript.InvokeMethod
Change By: Devin Nusbaum
Issue Type: Improvement Bug

jglick@cloudbees.com (JIRA)

unread,
Aug 1, 2019, 11:56:12 AM8/1/19
to jenkinsc...@googlegroups.com
Jesse Glick updated an issue

It does not seem like a great workaround either.

We already explicitly discourage domain-specific plugins from using GlobalVariable and implementing DSLs, but what ArtifactoryServer is doing is an additional complication: the returned object, or one of its resultant objects, is implemented in Java rather than CPS-transformed Groovy. I would consider this to be an unsupported and unsupportable trick.

Change By: Jesse Glick
Component/s: artifactory-plugin

jglick@cloudbees.com (JIRA)

unread,
Aug 1, 2019, 12:00:03 PM8/1/19
to jenkinsc...@googlegroups.com

Although I should say that since docker-workflow and pipeline-model-definition use the less problematic approach of exposing CPS-transformed Groovy, the receiverClass in those cases should not be loaded by a Jenkins plugin class loader as far as I know, so I do not believe such a patch would mask mistakes in those plugins, though it is worth confirming this.

(To confuse matters, pipeline-model-definition-plugin/pipeline-model-definition/src/main/groovy/ exists, but as far as Jenkins is concerned these are just plain old classes in the plugin. The CPS-transformed code that would be involved here is in pipeline-model-definition-plugin/pipeline-model-definition/src/main/groovy/**/*.groovy.

eyalb@jfrog.com (JIRA)

unread,
Aug 1, 2019, 12:12:02 PM8/1/19
to jenkinsc...@googlegroups.com

Jesse Glick, so what should we do to resolve this issue?

Can we perhaps allow specific steps to be excluded and avoid this message?

jglick@cloudbees.com (JIRA)

unread,
Aug 1, 2019, 12:30:04 PM8/1/19
to jenkinsc...@googlegroups.com

Best would be to reconsider what the artifactory plugin is doing, and simplify its implementation to be more normal. To the extent that is impossible for backward compatibility reasons, TBD—Devin Nusbaum can check effectiveness & safety of the above patch.

eyalb@jfrog.com (JIRA)

unread,
Aug 1, 2019, 10:01:02 PM8/1/19
to jenkinsc...@googlegroups.com

Can you please be more specific? What does simplifying the plugin and making it more normal mean? How can we maintain the existing APIs and avoid this warning message? 

eyalb@jfrog.com (JIRA)

unread,
Aug 7, 2019, 11:37:03 AM8/7/19
to jenkinsc...@googlegroups.com

Devin Nusbaum and Jesse Glick,

Can we perhaps add support for an optional variable, which can be set by pipeline steps, to indicate the step name? This should resolve the "false mismatch warning" issue.

Many pipelines out there are built and reply on the Artifactory pipeline APIs, so the solution we come up with cannot break the APIs. We'd be glad to create a PR, but we first need to know you're okay with this approach.

Looking forward to your feedback. Thanks!

jglick@cloudbees.com (JIRA)

unread,
Aug 7, 2019, 2:47:02 PM8/7/19
to jenkinsc...@googlegroups.com

The patch above seems like the safest and more general fix, if it indeed works. Needs testing.

eyalb@jfrog.com (JIRA)

unread,
Aug 7, 2019, 3:36:02 PM8/7/19
to jenkinsc...@googlegroups.com

Jesse Glick,

To which patch are you referring to? Is it my above suggestion? If so, we'll start working on a pull request.

jglick@cloudbees.com (JIRA)

unread,
Aug 7, 2019, 3:56:02 PM8/7/19
to jenkinsc...@googlegroups.com

No, to the patch in the comment by Devin Nusbaum in 2019-08-01.

robin@jfrog.com (JIRA)

unread,
Aug 13, 2019, 4:58:02 AM8/13/19
to jenkinsc...@googlegroups.com

Hi Jesse Glick and Devin Nusbaum,
I opened #314 with Devin's suggestion.
The patch solves our issue, workflow-cps-plugin tests are passing.
Thanks!

rwedd@cloudbees.com (JIRA)

unread,
Aug 14, 2019, 3:27:02 AM8/14/19
to jenkinsc...@googlegroups.com

Do we know when to expect the fix to come in i see #314 is failing 

jacob.mroz@gmail.com (JIRA)

unread,
Oct 1, 2019, 11:45:05 AM10/1/19
to jenkinsc...@googlegroups.com

We are seeing this issue in Jenkins 2.176.3, Artifactory Plugin 3.4.0, Groovy Plugin 2.74:

 

expected to call org.jfrog.hudson.pipeline.common.types.ArtifactoryServer.promote but wound up catching artifactoryPromoteBuild; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

hwhopema@us.ibm.com (JIRA)

unread,
Oct 17, 2019, 1:05:06 PM10/17/19
to jenkinsc...@googlegroups.com

We are also seeing this on Jenkins v2.190.1; Artifactory plugin v3.40; Groovy plugin v2.2
artifactoryUploadexpected to call org.jfrog.hudson.pipeline.common.types.ArtifactoryServer.upload but wound up catching artifactoryUpload; see:
 

dnusbaum@cloudbees.com (JIRA)

unread,
Oct 31, 2019, 4:40:08 PM10/31/19
to jenkinsc...@googlegroups.com
Devin Nusbaum resolved as Fixed
 

A fix for this issue was just released in Pipeline: Groovy Plugin version 2.75.

Change By: Devin Nusbaum
Status: Open Resolved
Resolution: Fixed
Released As: workflow-cps 2.75
Reply all
Reply to author
Forward
0 new messages