2

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 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?

8
  • 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.
    – jayhendren
    Commented Oct 9, 2017 at 18:43
  • @jayhendren I tried this, but unfortunately it seemed to have no effect. I still have the error. Commented Oct 9, 2017 at 19:14
  • Dang. Have you tried something like this: publisher = new publishToS3; publisher.call(src_file: ..., target_path..., ...); publisher.call(src_file: ..., ...)?
    – jayhendren
    Commented Oct 9, 2017 at 19:40
  • 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 Commented Oct 9, 2017 at 20:09
  • 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.
    – jayhendren
    Commented Oct 10, 2017 at 0:41

0

Browse other questions tagged or ask your own question.