Bitbucket Merge script working in Gobal Admin but not in Admin to repository

262 views Asked by At
// import the required libraries
import groovy.json.JsonOutput
import groovyx.net.http.HttpResponseException
import groovy.json.JsonSlurper


//set the commandline arguements in to global variables
def reqUrl = "<Bitbucket URL>"
def branchUAT = "<branchname>"
def branchRelease = "<branchname>"

def projects = mergeRequest.pullRequest.toRef.repository.project.key
String repoString = mergeRequest.pullRequest.toRef.repository
repos = repoString.tokenize("/")[1].tokenize("[")[0]
def branchSource = mergeRequest.pullRequest.fromRef.displayId
def branchDestination = mergeRequest.pullRequest.toRef.displayId


//define the required variables
def UAT_Commits_List = [] as String[]

def JSON_slurper = new groovy.json.JsonSlurper()

if (branchDestination == branchRelease) {
    def UAT_Commits_uri_curl = [ 'bash', '-c', "curl https://${reqUrl}/rest/api/1.0/projects/${projects}/repos/${repos}/compare/commits?from=${branchUAT}" ].execute().text
        def UAT_Commits_uri_result = JSON_slurper.parseText(UAT_Commits_uri_curl)
        try {
              def PRApproveArray = UAT_Commits_uri_result.values  
            PRApproveArray.each {
                UAT_Commits_List = UAT_Commits_List + it['id']
            }
        }
        catch(HttpResponseException e) {
                catchMethod(e)
        }

}

Error: You tried to call a method which is not allowed: groovy.json.JsonSlurper#parseText(java.lang.String) @ line 28, column 32. def UAT_Commits_uri_result = JSON_slurper.parseText(UAT_Commits_uri_curl)

0

There are 0 answers