Ошибка: java.io.NotSerializableException: org.apache.commons.httpclient.HttpClient GROOVY - PullRequest
0 голосов
/ 29 июня 2018

У меня проблема со скриптом Groovy.

Я делаю POST-вызов в Jenkins, чтобы получить доступ к результатам выполнения задания.

Результат возвращается мне в формате JSON. Поскольку я возвращал ошибку из объекта Non-Serializable, я использовал библиотеку import groovy.json.JsonSlurperClassic для анализа результата, и эта ошибка была устранена.

Но теперь он возвращает эту ошибку:

an exception which occurred:
    in field com.cloudbees.groovy.cps.impl.BlockScopeEnv.locals
    in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@6db9f892
    in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
    in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@5338e01a
    in field com.cloudbees.groovy.cps.impl.CallEnv.caller
    in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@65caceba
    in field com.cloudbees.groovy.cps.Continuable.e
    in object org.jenkinsci.plugins.workflow.cps.SandboxContinuable@5fc119bf
    in field org.jenkinsci.plugins.workflow.cps.CpsThread.program
    in object org.jenkinsci.plugins.workflow.cps.CpsThread@29f6e53a
    in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.threads
    in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@18a9b692
    in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@18a9b692
**Caused: java.io.NotSerializableException: org.apache.commons.httpclient.HttpClient**
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
    at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
    at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
    at org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
    at org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
    at java.util.HashMap.internalWriteEntries(HashMap.java:1785)
    at java.util.HashMap.writeObject(HashMap.java:1362)
    at sun.reflect.GeneratedMethodAccessor89.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:273)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
    at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
    at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
    at org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
    at org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
    at java.util.TreeMap.writeObject(TreeMap.java:2438)
    at sun.reflect.GeneratedMethodAccessor446.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:273)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
    at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:58)
    at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:111)
    at org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverWriter.lambda$writeObject$0(RiverWriter.java:144)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
    at org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverWriter.writeObject(RiverWriter.java:143)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:467)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:443)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgramIfPossible(CpsThreadGroup.java:430)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:367)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:82)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:243)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:231)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

Mi код:

def check_deployment(String proyecto, String country){

    proyecto = "#" + country + "-" + proyecto + "-" + env.BUILD_NUMBER

    // Credentials
    def username = commons_tasks.get_credentials("JENKINS_CD").user.toString()
    def password = commons_tasks.get_credentials("JENKINS_CD").password.toString()

    // Login
    def client = new HttpClient()
        client.state.setCredentials(
        new AuthScope( "tower.lares.dsd", 443, "realm"),
        new UsernamePasswordCredentials(username , password)
    )

    client.params.authenticationPreemptive = true

    def result_build = false
    def status_build = null

    while(!result_build){

        def post = new PostMethod("https://{URL_DOMAIN}/jenkins/job/{JOB_JENKINS}/api/json?depth=1")
        post.doAuthentication = true
        client.executeMethod(post)


        def response = post.getResponseBodyAsString()
        def jsonParse = new JsonSlurperClassic().parseText(response)


        def builds = jsonParse.builds;
        builds.find{
            if (proyecto == it.displayName){
                if (it.result != null){
                    result_build = true
                }
                status_build = it.result
                return true
            }
        }
    }


    if (status_build != "SUCCESS"){
        sh "exit 0"
    }else{
        sh "exit 1"
    }

}

Я не знаю, может ли проблема возникнуть из-за того, что я не закрыл клиента ... или есть что-то еще, что я могу сделать.

Я пытался поставить: @ NonCPS в начале класса, но не выполняет его напрямую.

Я также попытался поместить переменную результата как transient , чтобы сказать, что она не Serializable ... но я все еще получаю ошибку.

Кто-нибудь знает, что это может быть?

Большое спасибо

1 Ответ

0 голосов
/ 29 июня 2018

если я поставлю println (), который возвращает состояние некоторого поля, которое я ищу в JSON, оно не возвращает его мне. Я так понимаю, все, что не Serializable, не так ли?

Я не знаю, как должно быть поведение, когда я ставлю @ NonCPS , но если я, например, помещаю эхо в эти позиции, выполняется только первое:

@NonCPS
def check_deployment(String proyecto, String country){

    proyecto = "#es-integration-services-esb-dev-1.0.0-SNAPSHOT-"

    echo "Init call the Ansible's JOB"


    // Credentials
    def username = commons_tasks.get_credentials("JENKINS_CD").user.toString()
    def password = commons_tasks.get_credentials("JENKINS_CD").password.toString()


    // Login
    def client = new HttpClient()
        client.state.setCredentials(
        new AuthScope( "tower.lares.dsd", 443, "realm"),
        new UsernamePasswordCredentials(username , password)
    )

    echo "Client"
    client.params.authenticationPreemptive = true

    def result_build = false
    def status_build = null

    echo "While"
    while(!result_build){

        def post = new PostMethod("https://{URL_DOMAIN}/jenkins/job/{JOB_JENKINS}/api/json?depth=1")
        post.doAuthentication = true
        client.executeMethod(post)

        echo "Response"
        def response = post.getResponseBodyAsString()
        def jsonParse = new JsonSlurperClassic().parseText(response)

        echo "It JSON FOR"
        def builds = jsonParse.builds;
        builds.find{
            if (proyecto == it.displayName){
                println(" -- ID:  "+ it.id + " Nombre: " + it.displayName + " -> result is:  " + it.result + " ->  URL :  " + it.url + "Token: " + env.BUILD_NUMBER)
                if (it.result != null){
                    result_build = true
                }
                    status_build = it.result
                    return true
            }
        }
    }

    if (status_build != "SUCCESS"){
        sh "exit 0"
    }else{
        sh "exit 1"
    }

}

Журнал консоли:

[Pipeline] echo
**Init call the Ansible's JOB**
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/...
[Pipeline] {
[Pipeline] script
[Pipeline] {
[Pipeline] echo
[Pipeline] cleanWs
[WS-CLEANUP] Deleting project workspace...[WS-CLEANUP] done
[Pipeline] echo
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: SUCCESS

Просто покажите мне первый эхо "Инициация вызова ИСО",

Спасибо за ответ!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...