java.io.NotSerializableException: sun.net.www.protocol.https.HttpsURLConnectionImpl in Jenkins pipeline
up vote
1
down vote
favorite
There are plenty of discussion about what it means and what to do about it, however the main solution of using @NonCPS
doesn't seem to work. Here's the relevant piece of the code:
@NonCPS
def restCall(String method, String resource, String data = '') {
def URL url = new URL("${Params.REST_BASE_URI}/${resource}")
def HttpURLConnection connection = url.openConnection()
withCredentials([usernamePassword(credentialsId: 'restful-api', passwordVariable: 'RA_PASS', usernameVariable: 'RA_USER')]) {
String encoded = Base64.getEncoder().encodeToString(("${env.RA_USER}:${env.RA_PASS}").getBytes(StandardCharsets.UTF_8))
connection.setRequestProperty("Authorization", "Basic ${encoded}");
}
connection.setRequestProperty("content-type", "application/json");
connection.setRequestMethod(method)
connection.doOutput = true
if (data != '') {
def writer = new OutputStreamWriter(connection.outputStream)
writer.write(data)
writer.flush()
writer.close()
}
connection.connect();
def statusCode = connection.responseCode
if (statusCode != 200 && statusCode != 201) {
throw new Exception(connection.getErrorSteam().text)
}
return connection.content.text
}
Note that it does have @NonCPS
on the function. However executing this still produces the same error:
an exception which occurred:
in field groovy.lang.Reference.value
in object groovy.lang.Reference@1375b00
in field WorkflowScript$_bitbucketCall_closure1.connection
in object WorkflowScript$_bitbucketCall_closure1@b3001c
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
Caused: java.io.NotSerializableException: sun.net.www.protocol.https.HttpsURLConnectionImpl
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at ...
How can I solve it?
jenkins jenkins-pipeline
add a comment |
up vote
1
down vote
favorite
There are plenty of discussion about what it means and what to do about it, however the main solution of using @NonCPS
doesn't seem to work. Here's the relevant piece of the code:
@NonCPS
def restCall(String method, String resource, String data = '') {
def URL url = new URL("${Params.REST_BASE_URI}/${resource}")
def HttpURLConnection connection = url.openConnection()
withCredentials([usernamePassword(credentialsId: 'restful-api', passwordVariable: 'RA_PASS', usernameVariable: 'RA_USER')]) {
String encoded = Base64.getEncoder().encodeToString(("${env.RA_USER}:${env.RA_PASS}").getBytes(StandardCharsets.UTF_8))
connection.setRequestProperty("Authorization", "Basic ${encoded}");
}
connection.setRequestProperty("content-type", "application/json");
connection.setRequestMethod(method)
connection.doOutput = true
if (data != '') {
def writer = new OutputStreamWriter(connection.outputStream)
writer.write(data)
writer.flush()
writer.close()
}
connection.connect();
def statusCode = connection.responseCode
if (statusCode != 200 && statusCode != 201) {
throw new Exception(connection.getErrorSteam().text)
}
return connection.content.text
}
Note that it does have @NonCPS
on the function. However executing this still produces the same error:
an exception which occurred:
in field groovy.lang.Reference.value
in object groovy.lang.Reference@1375b00
in field WorkflowScript$_bitbucketCall_closure1.connection
in object WorkflowScript$_bitbucketCall_closure1@b3001c
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
Caused: java.io.NotSerializableException: sun.net.www.protocol.https.HttpsURLConnectionImpl
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at ...
How can I solve it?
jenkins jenkins-pipeline
Marking the method as@NonCPS
would only apply to the method itself I would think. That would then not apply to the scope ofURL.openConnection()
, which does not seem to be serializable. That being said, I hope someone knows how to solve this because global vars to create REST API calls are going to be rather helpful in jenkins-pipeline.
– Matt Schuchard
Nov 8 at 13:37
What I can see is that you’re calling some pipeline methods from within the NonCPS method. That’s neither supported or will work. However I think that the reason for the exception is not to search here but in the remaining code which is not marked as NonCPS. To support you there please submit the calling code as well.
– Joerg S
Nov 10 at 10:31
@I don't think calling code has anything to do with it, as the stacktrace points toHTTPUrlConnection
class. In any event, an example calling code would bedef result = restCall('GET', 'info')
– Aleks G
Nov 12 at 11:28
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
There are plenty of discussion about what it means and what to do about it, however the main solution of using @NonCPS
doesn't seem to work. Here's the relevant piece of the code:
@NonCPS
def restCall(String method, String resource, String data = '') {
def URL url = new URL("${Params.REST_BASE_URI}/${resource}")
def HttpURLConnection connection = url.openConnection()
withCredentials([usernamePassword(credentialsId: 'restful-api', passwordVariable: 'RA_PASS', usernameVariable: 'RA_USER')]) {
String encoded = Base64.getEncoder().encodeToString(("${env.RA_USER}:${env.RA_PASS}").getBytes(StandardCharsets.UTF_8))
connection.setRequestProperty("Authorization", "Basic ${encoded}");
}
connection.setRequestProperty("content-type", "application/json");
connection.setRequestMethod(method)
connection.doOutput = true
if (data != '') {
def writer = new OutputStreamWriter(connection.outputStream)
writer.write(data)
writer.flush()
writer.close()
}
connection.connect();
def statusCode = connection.responseCode
if (statusCode != 200 && statusCode != 201) {
throw new Exception(connection.getErrorSteam().text)
}
return connection.content.text
}
Note that it does have @NonCPS
on the function. However executing this still produces the same error:
an exception which occurred:
in field groovy.lang.Reference.value
in object groovy.lang.Reference@1375b00
in field WorkflowScript$_bitbucketCall_closure1.connection
in object WorkflowScript$_bitbucketCall_closure1@b3001c
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
Caused: java.io.NotSerializableException: sun.net.www.protocol.https.HttpsURLConnectionImpl
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at ...
How can I solve it?
jenkins jenkins-pipeline
There are plenty of discussion about what it means and what to do about it, however the main solution of using @NonCPS
doesn't seem to work. Here's the relevant piece of the code:
@NonCPS
def restCall(String method, String resource, String data = '') {
def URL url = new URL("${Params.REST_BASE_URI}/${resource}")
def HttpURLConnection connection = url.openConnection()
withCredentials([usernamePassword(credentialsId: 'restful-api', passwordVariable: 'RA_PASS', usernameVariable: 'RA_USER')]) {
String encoded = Base64.getEncoder().encodeToString(("${env.RA_USER}:${env.RA_PASS}").getBytes(StandardCharsets.UTF_8))
connection.setRequestProperty("Authorization", "Basic ${encoded}");
}
connection.setRequestProperty("content-type", "application/json");
connection.setRequestMethod(method)
connection.doOutput = true
if (data != '') {
def writer = new OutputStreamWriter(connection.outputStream)
writer.write(data)
writer.flush()
writer.close()
}
connection.connect();
def statusCode = connection.responseCode
if (statusCode != 200 && statusCode != 201) {
throw new Exception(connection.getErrorSteam().text)
}
return connection.content.text
}
Note that it does have @NonCPS
on the function. However executing this still produces the same error:
an exception which occurred:
in field groovy.lang.Reference.value
in object groovy.lang.Reference@1375b00
in field WorkflowScript$_bitbucketCall_closure1.connection
in object WorkflowScript$_bitbucketCall_closure1@b3001c
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@144b2a6
Caused: java.io.NotSerializableException: sun.net.www.protocol.https.HttpsURLConnectionImpl
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at ...
How can I solve it?
jenkins jenkins-pipeline
jenkins jenkins-pipeline
asked Nov 8 at 10:31
Aleks G
41.8k18120188
41.8k18120188
Marking the method as@NonCPS
would only apply to the method itself I would think. That would then not apply to the scope ofURL.openConnection()
, which does not seem to be serializable. That being said, I hope someone knows how to solve this because global vars to create REST API calls are going to be rather helpful in jenkins-pipeline.
– Matt Schuchard
Nov 8 at 13:37
What I can see is that you’re calling some pipeline methods from within the NonCPS method. That’s neither supported or will work. However I think that the reason for the exception is not to search here but in the remaining code which is not marked as NonCPS. To support you there please submit the calling code as well.
– Joerg S
Nov 10 at 10:31
@I don't think calling code has anything to do with it, as the stacktrace points toHTTPUrlConnection
class. In any event, an example calling code would bedef result = restCall('GET', 'info')
– Aleks G
Nov 12 at 11:28
add a comment |
Marking the method as@NonCPS
would only apply to the method itself I would think. That would then not apply to the scope ofURL.openConnection()
, which does not seem to be serializable. That being said, I hope someone knows how to solve this because global vars to create REST API calls are going to be rather helpful in jenkins-pipeline.
– Matt Schuchard
Nov 8 at 13:37
What I can see is that you’re calling some pipeline methods from within the NonCPS method. That’s neither supported or will work. However I think that the reason for the exception is not to search here but in the remaining code which is not marked as NonCPS. To support you there please submit the calling code as well.
– Joerg S
Nov 10 at 10:31
@I don't think calling code has anything to do with it, as the stacktrace points toHTTPUrlConnection
class. In any event, an example calling code would bedef result = restCall('GET', 'info')
– Aleks G
Nov 12 at 11:28
Marking the method as
@NonCPS
would only apply to the method itself I would think. That would then not apply to the scope of URL.openConnection()
, which does not seem to be serializable. That being said, I hope someone knows how to solve this because global vars to create REST API calls are going to be rather helpful in jenkins-pipeline.– Matt Schuchard
Nov 8 at 13:37
Marking the method as
@NonCPS
would only apply to the method itself I would think. That would then not apply to the scope of URL.openConnection()
, which does not seem to be serializable. That being said, I hope someone knows how to solve this because global vars to create REST API calls are going to be rather helpful in jenkins-pipeline.– Matt Schuchard
Nov 8 at 13:37
What I can see is that you’re calling some pipeline methods from within the NonCPS method. That’s neither supported or will work. However I think that the reason for the exception is not to search here but in the remaining code which is not marked as NonCPS. To support you there please submit the calling code as well.
– Joerg S
Nov 10 at 10:31
What I can see is that you’re calling some pipeline methods from within the NonCPS method. That’s neither supported or will work. However I think that the reason for the exception is not to search here but in the remaining code which is not marked as NonCPS. To support you there please submit the calling code as well.
– Joerg S
Nov 10 at 10:31
@I don't think calling code has anything to do with it, as the stacktrace points to
HTTPUrlConnection
class. In any event, an example calling code would be def result = restCall('GET', 'info')
– Aleks G
Nov 12 at 11:28
@I don't think calling code has anything to do with it, as the stacktrace points to
HTTPUrlConnection
class. In any event, an example calling code would be def result = restCall('GET', 'info')
– Aleks G
Nov 12 at 11:28
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205882%2fjava-io-notserializableexception-sun-net-www-protocol-https-httpsurlconnectioni%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Marking the method as
@NonCPS
would only apply to the method itself I would think. That would then not apply to the scope ofURL.openConnection()
, which does not seem to be serializable. That being said, I hope someone knows how to solve this because global vars to create REST API calls are going to be rather helpful in jenkins-pipeline.– Matt Schuchard
Nov 8 at 13:37
What I can see is that you’re calling some pipeline methods from within the NonCPS method. That’s neither supported or will work. However I think that the reason for the exception is not to search here but in the remaining code which is not marked as NonCPS. To support you there please submit the calling code as well.
– Joerg S
Nov 10 at 10:31
@I don't think calling code has anything to do with it, as the stacktrace points to
HTTPUrlConnection
class. In any event, an example calling code would bedef result = restCall('GET', 'info')
– Aleks G
Nov 12 at 11:28