将每个阶段的数据从 jenkins 管道推送到 influx db 时如何修复 java.io.NotSerializable 异常?
How to fix java.io.NotSerializable exception when pushing each stage data from jenkins pipeline to influx db?
我正在尝试将阶段数据从 Jenkins 管道推送到 influx 数据库,但出现如下问题
问题:在 jenkin 构建控制台输出中,在每个阶段之后,我看到:java.io.NotSerializableException:sun.net.www.protocol.http.HttpURLConnection
詹金斯管道 2.150.2
InfluxDB 1.6.2
任何建议都会有所帮助。我是这个话题的新手。
注意:@NonCPS注解我已经注释掉了。如果我取消注释,那么它只发送第一阶段数据并退出并且无法迭代具有 20 个阶段数据的循环。
//Maps for Field type columns
myDataField1 = [:]
myDataField2 = [:]
myDataField3 = [:]
//Maps for Custom Field measurements
myCustomDataFields1 = [:]
myCustomDataFields2 = [:]
myCustomDataFields3 = [:]
//Maps for Tag type columns
myDataTag1 = [:]
myDataTag2 = [:]
myDataTag3 = [:]
//Maps for Custom Tag measurements
myCustomDataTags1 = [:]
myCustomDataTags2 = [:]
myCustomDataTags3 = [:]
//@NonCPS
def pushStageData() {
def url_string = "${JENKINS_URL}job/ENO_ENG_TP/job/R421/13/wfapi/describe"
def get = new URL(url_string).openConnection();
get.addRequestProperty ("User-Agent","Mozilla/4.0");
get.addRequestProperty("Authorization", "Basic dZXZvceDIwMTk=");
//fetching the contents of the endpoint URL
def jsonText = get.getInputStream().getText();
//converting the text into JSON object using
JsonSlurperClassic
def jsonObject = new JsonSlurperClassic().parseText(jsonText)
// Extracting the details of all the stages present in that particular build number
for (int i=0; i<jsonObject.stages.size()-1; i++){ //size-1 to ignore the post stage
//populating the field type columns of InfluxDB measurements and pushing them to the map called myDataField1
def size = jsonObject.stages.size()-1
myDataField1['result'] = jsonObject.stages[i].status
myDataField1['duration'] =
jsonObject.stages[i].durationMillis
myDataField1['stage_name'] = jsonObject.stages[i].name
//populating the tag type columns of InfluxDB
measurements and pushing them to the map called
myDataTag1
myDataTag1['result_tag'] = jsonObject.stages[i].status
myDataTag1['stage_name_tag'] = jsonObject.stages[i].name
//assigning field type columns to the measurement called CustomData
myCustomDataFields1['CustomData'] = myDataField1
//assigning tag type columns to the measurement called CustomData
myCustomDataTags1['CustomData'] = myDataTag1
//Push the data into influx instance
try
{ step([$class: 'InfluxDbPublisher', target: 'jenkins_data', customPrefix: null, customDataMapTags: myCustomDataTags1]) }
catch (err)
{ println ("pushStagData exception: " + err) }
}
}
预期:我想将jenkins管道数据的各个阶段推送到influx db。
尝试使用 jenkins 的标准方法,而不是手动创建对象。您可以使用 httpRequest instead of URL. This should fix exception you are getting. You can also use readJson 而不是 JsonSlurperClassic(后者是可选的,因为经典的 slurper 实际上是可序列化的)。
您只需要将 get
显式设置为 null 以确保有 none 不可序列化的对象被实例化。
def jsonText = get.getInputStream().getText();
get = null;
我正在尝试将阶段数据从 Jenkins 管道推送到 influx 数据库,但出现如下问题
问题:在 jenkin 构建控制台输出中,在每个阶段之后,我看到:java.io.NotSerializableException:sun.net.www.protocol.http.HttpURLConnection
詹金斯管道 2.150.2 InfluxDB 1.6.2
任何建议都会有所帮助。我是这个话题的新手。
注意:@NonCPS注解我已经注释掉了。如果我取消注释,那么它只发送第一阶段数据并退出并且无法迭代具有 20 个阶段数据的循环。
//Maps for Field type columns
myDataField1 = [:]
myDataField2 = [:]
myDataField3 = [:]
//Maps for Custom Field measurements
myCustomDataFields1 = [:]
myCustomDataFields2 = [:]
myCustomDataFields3 = [:]
//Maps for Tag type columns
myDataTag1 = [:]
myDataTag2 = [:]
myDataTag3 = [:]
//Maps for Custom Tag measurements
myCustomDataTags1 = [:]
myCustomDataTags2 = [:]
myCustomDataTags3 = [:]
//@NonCPS
def pushStageData() {
def url_string = "${JENKINS_URL}job/ENO_ENG_TP/job/R421/13/wfapi/describe"
def get = new URL(url_string).openConnection();
get.addRequestProperty ("User-Agent","Mozilla/4.0");
get.addRequestProperty("Authorization", "Basic dZXZvceDIwMTk=");
//fetching the contents of the endpoint URL
def jsonText = get.getInputStream().getText();
//converting the text into JSON object using
JsonSlurperClassic
def jsonObject = new JsonSlurperClassic().parseText(jsonText)
// Extracting the details of all the stages present in that particular build number
for (int i=0; i<jsonObject.stages.size()-1; i++){ //size-1 to ignore the post stage
//populating the field type columns of InfluxDB measurements and pushing them to the map called myDataField1
def size = jsonObject.stages.size()-1
myDataField1['result'] = jsonObject.stages[i].status
myDataField1['duration'] =
jsonObject.stages[i].durationMillis
myDataField1['stage_name'] = jsonObject.stages[i].name
//populating the tag type columns of InfluxDB
measurements and pushing them to the map called
myDataTag1
myDataTag1['result_tag'] = jsonObject.stages[i].status
myDataTag1['stage_name_tag'] = jsonObject.stages[i].name
//assigning field type columns to the measurement called CustomData
myCustomDataFields1['CustomData'] = myDataField1
//assigning tag type columns to the measurement called CustomData
myCustomDataTags1['CustomData'] = myDataTag1
//Push the data into influx instance
try
{ step([$class: 'InfluxDbPublisher', target: 'jenkins_data', customPrefix: null, customDataMapTags: myCustomDataTags1]) }
catch (err)
{ println ("pushStagData exception: " + err) }
}
}
预期:我想将jenkins管道数据的各个阶段推送到influx db。
尝试使用 jenkins 的标准方法,而不是手动创建对象。您可以使用 httpRequest instead of URL. This should fix exception you are getting. You can also use readJson 而不是 JsonSlurperClassic(后者是可选的,因为经典的 slurper 实际上是可序列化的)。
您只需要将 get
显式设置为 null 以确保有 none 不可序列化的对象被实例化。
def jsonText = get.getInputStream().getText();
get = null;