Hi all, 

I have a shared library that extends the pipeline.

Inside of my class I have a variable that is a Gstring. 


If I call a method after this variable, the Jenkinsfile produces an error when 
running
class SlackNotifierImpl implements SlackNotifier, Serializable {

    ....

    final def currentBuildJob = "${script.env.JOB_NAME} 
${script.env.BUILD_NUMBER}"

    def variable = someMethod()

}

but, if I do something else after defining the variable, there is no problem
class SlackNotifierImpl implements SlackNotifier, Serializable {

    ....

    final def currentBuildJob = "${script.env.JOB_NAME} 
${script.env.BUILD_NUMBER}"

    def variable = 'xxx'

}

The error produced is the following: 

* sometimes, I get this: 

com.cloudbees.groovy.cps.impl.CpsCallableInvocation

* some other times, I get this:

java.lang.UnsupportedOperationException: Refusing to marshal 
org.codehaus.groovy.runtime.GStringImpl for security reasons
        at 
hudson.util.XStream2$BlacklistedTypesConverter.marshal(XStream2.java:452)
        at 
com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
        at 
com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
        at 
com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
        at 
hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:265)
        at 
hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:252)
Caused: java.lang.RuntimeException: Failed to serialize 
org.ecg.es.jenkins.pipeline.shared.library.helpers.notification.SlackNotifierImpl#currentBuildJob


The Jenkinsfile is the following: 


Jenkinsfile (uses declarative):

#!/usr/bin/env groovy
/* 
Template for Sending Slack Notifications with the Result of the Build 
*/
import com.lesfurets.jenkins.unit.global.lib.Library
@Library('pipeline-library@development') import 
org.ecg.es.jenkins.pipeline.shared.library.LibraryFacade

def library = new LibraryFacade(this)

pipeline {
    agent any
    stages {            
        stage('Build') {
            steps {
                echo 'Building..'
            }
        }
    }    
    post {
            success {
                echo 'Build was succesful.'
                script {
                    library.sendSuccessfulBuildNotificationToSlack()
                }
        }
        changed {
            echo 'Build status has changed.'
            script {
                    library.sendChangedBuildStatusNotificationToSlack()
            }
        }
        failure {
                echo 'Build was not succesful.'
                script {
                     library.sendFailedBuildNotificationToSlack()
                }
        }

    }
}

def testMethod(){
    echo 'Testing this works'
}



Any idea of what is wrong here?

Thanks, best
C.




-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/746104da-909b-47b6-8c93-763108648f1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to