Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate class definition for OwnershipGlobalVariableImpl #84

Open
gpxricky opened this issue Jul 29, 2020 · 5 comments
Open

Duplicate class definition for OwnershipGlobalVariableImpl #84

gpxricky opened this issue Jul 29, 2020 · 5 comments
Labels

Comments

@gpxricky
Copy link

Hi,
I'm using the plugin in a Declarative Pipeline. I access the job owners in two different stages, in a normal build stage and in the cleanup stage.
Unfortunately I now sometimes get the following error:

java.lang.LinkageError: loader (instance of  org/jenkinsci/plugins/workflow/cps/CpsGroovyShell$CleanGroovyClassLoader): attempted  duplicate class definition for name: "org/jenkinsci/plugins/ownership/model/OwnershipGlobalVariableImpl"

I don't think it has something to do with it, but the problem appeared only (?) after introducing the feature of sequential stages. However, the ownership plugin is only accessed within one of the two stages blocks.

Below you find the functions that I'm using in a custom step of my shared library. This code is accessed two times, in the normal stage and in the cleanup stage:

  • ownership.job.ownershipEnabled
  • ownership.job.primaryOwnerEmail
  • ownership.job.secondaryOwnerEmails

I'm using version 0.12.1 of the plugin.

@oleg-nenashev
Copy link
Member

Looks like a valid bug, not sure whateher the Ownership Plugin is a root cause. I will try to investigate

@gpxricky
Copy link
Author

gpxricky commented Dec 8, 2020

Did you have time to investigate the issue?

Below is a more detailed error message:

java.lang.LinkageError: loader (instance of  org/jenkinsci/plugins/workflow/cps/CpsGroovyShell$CleanGroovyClassLoader): attempted  duplicate class definition for name: "org/jenkinsci/plugins/ownership/model/OwnershipGlobalVariableImpl"
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at groovy.lang.GroovyClassLoader.access$400(GroovyClassLoader.java:62)
	at groovy.lang.GroovyClassLoader$ClassCollector.createClass(GroovyClassLoader.java:500)
	at groovy.lang.GroovyClassLoader$ClassCollector.onClassNode(GroovyClassLoader.java:517)
	at groovy.lang.GroovyClassLoader$ClassCollector.call(GroovyClassLoader.java:521)
	at org.codehaus.groovy.control.CompilationUnit$17.call(CompilationUnit.java:834)
	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1065)
	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.GroovyClassLoader.parseClass(GroovyClassLoader.java:254)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:250)
	at groovy.lang.GroovyClassLoader.recompile(GroovyClassLoader.java:766)
	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:718)
	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:787)
	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:775)
	at org.jenkinsci.plugins.ownership.model.workflow.OwnershipGlobalVariable.getValue(OwnershipGlobalVariable.java:65)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.getProperty(CpsScript.java:135)
	at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:456)
	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:39)
	at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)

@gpxricky
Copy link
Author

gpxricky commented Dec 8, 2020

This is a build pipeline that is able to produce the issue (not always, but for me nearly 50%):

#!groovy

//region Shared Libraries

@Library('mysharedlib@latest') _

//endregion


//region Declarative Pipeline

pipeline {
  options {
    // Prepend all console outputs with a timestamp
    timestamps()
  }

  agent agent { label 'mylabel' }

  stages {
    stage('Perform action a') {
      steps {
        script {
          // call global variable that internally accesses ownership.job
          runActionA()
        }
      }
    } // stage
  } // stages

  post {
    cleanup {
      script {
        // call global variable that internally accesses ownership.job
        runActionB()
      }
    } // cleanup
  } // post
} // pipeline

//endregion

@oleg-nenashev
Copy link
Member

Hi @gpxricky . My apologies, I forgot about this TODO item. Added it to my list .

Looks like it is similar to of https://issues.jenkins.io/browse/JENKINS-48628 / https://issues.jenkins.io/browse/JENKINS-50171 , which are related to use of packages in global variables. jenkinsci/workflow-cps-plugin#214 from @abayer fixed a similar issue in loadedScripts. Likely a similar script is needed for variables.

@gpxricky
Copy link
Author

gpxricky commented Dec 8, 2020

Thanks, Oleg. Is there any workaround you can think of that I can access the information two times in my pipeline?

Edited: the following code within my shared library seems to work fine:

import com.synopsys.arc.jenkins.plugins.ownership.jobs.JobOwnerHelper

def runActionA()
{
  def ownershipDescription = JobOwnerHelper.Instance.getOwnershipDescription(currentBuild.rawBuild.parent)
  if (ownershipDescription.ownershipEnabled) {
    return ownershipDescription.primaryOwnerEmail
  }

  return null
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants