Body: <p>I've got a jenkinsfile which is breaking on a <em>second</em> call to a custom library step. These calls are made inside another custom library step. I'm not sure if this is something not supported or what.
  Here's the step publishInstaller.groovy file</p>
  
  <pre><code>#!/usr/bin/env groovy
  package com.seven10;
  
  import com.seven10.Builder
  
  def call(hashmap) 
  {
      def role_name = hashmap['role_name']
      def target_path = hashmap['target_path']
      def builder = hashmap['builder']
      def src_path = hashmap.get('src_path', 'installer')
      def src_file = hashmap.get('src_file', "${src_path}\\${role_name}.exe")
      def file_name = builder.getFriendlyName(role_name)
  
      echo 'Uploading installer: ' + src_file + ' as ' + file_name
      publishToS3 src_file: src_file, target_path: "${target_path}/${BRANCH_NAME}/${file_name}.exe"
      publishToS3 src_file: src_file, target_path: "${target_path}/${BRANCH_NAME}/latest.exe"
  }
  </code></pre>
  
  <p>Here's the publishToS3.groovy file</p>
  
  <pre><code>#!/usr/bin/env groovy
  package com.seven10;
  
  import com.seven10.Builder;
  
  def call(hashmap){
      def src_file = hashmap['src_file']
      def target_path = hashmap['target_path']
      def bucket_name = hashmap.get('bucket_name', Builder.TARGET_BUCKET)
      def region = hashmap.get('region', '....')
      def credentials = hashmap.get('credentials', '....')
  
      withAWS(credentials: credentials, region: region) {
          s3Upload bucket: bucket_name, file: src_file, path: target_path
      }
  }
  </code></pre>
  
  <p>what is happening is that the first call to publishToS3 is successful, but when it calls the function the second time I get</p>
  
  <pre><code>loader (instance of  org/jenkinsci/plugins/workflow/cps/CpsGroovyShell$CleanGroovyClassLoader): attempted  duplicate class definition for name: "com/seven10/publishToS3"
  </code></pre>
  
  <p>The documentation for <a href="https://github.com/jenkinsci/pipeline-aws-plugin#s3upload" rel="nofollow noreferrer">s3Upload</a> since 1.1 long-running steps are asynchronous. I am wondering if this is causing the publishToS3 method to not truly exit and that is why the error is occurring.</p>
  
  <p>At any rate, I could really use some help on this, so my question is: How do I fix that thing I just said?</p>
  
Comments: CC BY-SA 3.0
Comments: 2017-10-09T18:43:07.373Z
Comments: Hmmmm, have you tried adding `import com.seven10.publishToS3` to `publishInstaller.groovy`? I'm curious if Jenkins is trying to implicitly load `com.seven10.publishToS3` twice, which might cause that error.
Comments: jayhendren
Comments: CC BY-SA 3.0
Comments: 2017-10-09T19:14:11.090Z
Comments: @jayhendren I tried this, but unfortunately it seemed to have no effect. I still have the error.
Comments: Kevin Milner
Comments: CC BY-SA 3.0
Comments: 2017-10-09T19:40:29.313Z
Comments: Dang. Have you tried something like this: `publisher = new publishToS3; publisher.call(src_file: ..., target_path..., ...); publisher.call(src_file: ..., ...)`?
Comments: jayhendren
Comments: CC BY-SA 3.0
Comments: 2017-10-09T20:09:57.647Z
Comments: I haven't tried that. --I was trying to avoid having to put stuff in a script block, but thats better than it not working at all.-- let me give that a shot
Comments: Kevin Milner
Comments: CC BY-SA 3.0
Comments: 2017-10-09T20:51:14.680Z
Comments: Not sure what you mean.  That doesn't involve a script block at all.
Comments: jayhendren
Comments: CC BY-SA 3.0
Comments: 2017-10-09T20:55:52.363Z
Comments: Yeah I know, I realized I was wrong but it was after 5 minutes so I couldn't edit.
  Ok, so with the latest changes suggested I get what appears to be an error about serialization: 
  `Caused: java.io.NotSerializableException: org.codehaus.groovy.control.ErrorCollector`
Comments: Kevin Milner
Comments: CC BY-SA 3.0
Comments: 2017-10-09T20:57:34.917Z
Comments: oh, and again the first call works, its on the second where its throwing this new error
Comments: Kevin Milner
Comments: CC BY-SA 3.0
Comments: 2017-10-10T00:41:15.977Z
Comments: The serialization error is because Jenkins sandboxes Groovy scripts and prevents them from using certain data types. You can disable the sandbox in your job configuration.  There are other ways around the sandbox limitations as well, which are too complicated to discuss in these comments.
Comments: jayhendren
Tags: <jenkins><jenkins-pipeline><jenkinsfile>
Title: Duplicate Class Definition when calling library code
UserDisplayName: Kevin Milner
ThreadText: # Duplicate Class Definition when calling library code
  
  (Asked by: username_0 on 2017-10-06)
  
  I've got a jenkinsfile which is breaking on a *second* call to a custom library step. These calls are made inside another custom library step. I'm not sure if this is something not supported or what.
  Here's the step publishInstaller.groovy file
  
  ```
  #!/usr/bin/env groovy
  package com.seven10;
  
  import com.seven10.Builder
  
  def call(hashmap) 
  {
      def role_name = hashmap['role_name']
      def target_path = hashmap['target_path']
      def builder = hashmap['builder']
      def src_path = hashmap.get('src_path', 'installer')
      def src_file = hashmap.get('src_file', "${src_path}\\${role_name}.exe")
      def file_name = builder.getFriendlyName(role_name)
  
      echo 'Uploading installer: ' + src_file + ' as ' + file_name
      publishToS3 src_file: src_file, target_path: "${target_path}/${BRANCH_NAME}/${file_name}.exe"
      publishToS3 src_file: src_file, target_path: "${target_path}/${BRANCH_NAME}/latest.exe"
  }
  
  ```
  
  Here's the publishToS3.groovy file
  
  ```
  #!/usr/bin/env groovy
  package com.seven10;
  
  import com.seven10.Builder;
  
  def call(hashmap){
      def src_file = hashmap['src_file']
      def target_path = hashmap['target_path']
      def bucket_name = hashmap.get('bucket_name', Builder.TARGET_BUCKET)
      def region = hashmap.get('region', '....')
      def credentials = hashmap.get('credentials', '....')
  
      withAWS(credentials: credentials, region: region) {
          s3Upload bucket: bucket_name, file: src_file, path: target_path
      }
  }
  
  ```
  
  what is happening is that the first call to publishToS3 is successful, but when it calls the function the second time I get
  
  ```
  loader (instance of  org/jenkinsci/plugins/workflow/cps/CpsGroovyShell$CleanGroovyClassLoader): attempted  duplicate class definition for name: "com/seven10/publishToS3"
  
  ```
  
  The documentation for [s3Upload](https://github.com/jenkinsci/pipeline-aws-plugin#s3upload) since 1.1 long-running steps are asynchronous. I am wondering if this is causing the publishToS3 method to not truly exit and that is why the error is occurring.
  
  At any rate, I could really use some help on this, so my question is: How do I fix that thing I just said?
  
  **Tags:** jenkins, jenkins-pipeline, jenkinsfile
  
  > **Comments:**
  > **username_1**: Hmmmm, have you tried adding `import com.seven10.publishToS3` to `publishInstaller.groovy`? I'm curious if Jenkins is trying to implicitly load `com.seven10.publishToS3` twice, which might cause that error.  
  > **username_0**: @username_1 I tried this, but unfortunately it seemed to have no effect. I still have the error.  
  > **username_1**: Dang. Have you tried something like this: `publisher = new publishToS3; publisher.call(src_file: ..., target_path..., ...); publisher.call(src_file: ..., ...)`?  
  > **username_0**: I haven't tried that. --I was trying to avoid having to put stuff in a script block, but thats better than it not working at all.-- let me give that a shot  
  > **username_1**: Not sure what you mean.  That doesn't involve a script block at all.  
  > **username_0**: Yeah I know, I realized I was wrong but it was after 5 minutes so I couldn't edit. Ok, so with the latest changes suggested I get what appears to be an error about serialization:  `Caused: java.io.NotSerializableException: org.codehaus.groovy.control.ErrorCollector`  
  > **username_0**: oh, and again the first call works, its on the second where its throwing this new error  
  > **username_1**: The serialization error is because Jenkins sandboxes Groovy scripts and prevents them from using certain data types. You can disable the sandbox in your job configuration.  There are other ways around the sandbox limitations as well, which are too complicated to discuss in these comments.  
  
  ---
  
  ## 0 answers
  
  