0

这是我创建的用于处理来自 API 的 json 的管道。但是,当我运行它时,它在第一个循环后失败。

import groovy.json.JsonSlurper
pipeline {
agent none

stages {
    stage('Query Pull Requests'){
        steps{
            script {
                def response =  httpRequest authentication: 'BitbucketAuth', url: "https://api.bitbucket.org/2.0/repositories/repo-name/pullrequests"
                echo "Status: ${response.status}"
                def json = new JsonSlurper().parseText(content)
                def pullrequests = json.values;
                for (int i = 0; i < pullrequests.size(); i++) {
                    stage("Processing Pull Request ID : ${pullrequests[i].id}"){
                        echo "${pullrequests[i].source.branch.name}"
                        echo "${pullrequests[i].destination.branch.name}"
                        echo "${pullrequests[i].destination.repository.full_name}"
                    }
                }
            }
        }
    }
  }
}

这是我得到的错误

詹金斯版 2.107

4

1 回答 1

1

一旦不再需要该变量,就必须将“ json ”变量取消设置为空:-

def json = new JsonSlurper().parseText(content)
def pullrequests = json.values;
for (int i = 0; i < pullrequests.size(); i++) {
  stage("Processing Pull Request ID : ${pullrequests[i].id}"){
  echo "${pullrequests[i].source.branch.name}"
  echo "${pullrequests[i].destination.branch.name}"
  echo "${pullrequests[i].destination.repository.full_name}"
}

// unset response because it's not serializable and Jenkins throws NotSerializableException.
json = null

有关更多信息,请点击此链接

于 2019-11-01T09:33:20.257 回答