Skip to content

Commit

Permalink
Initial version of setBuildStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
serverhorror committed Oct 22, 2023
1 parent dd4c83a commit 8936330
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/org/ods/services/BitbucketService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,37 @@ class BitbucketService {
}
}

@NonCPS
void setBuildStatus_(String buildUrl, String gitCommit, String state, String buildName) {

// see: https://developer.atlassian.com/server/bitbucket/rest/v808/api-group-builds-and-deployments/#api-api-latest-projects-projectkey-repos-repositoryslug-commits-commitid-builds-post
def payload = [
// key: The string referring to this branch plan/job
key : "...",
// state: The build status state, one of: "SUCCESSFUL", "FAILED", "INPROGRESS"
state: state,
// url: URL referring to the build result page in the CI tool.
url : buildUrl
]

def json = new groovy.json.JsonBuilder(payload)
def headers = buildHeaders(token)
def httpRequest = Unirest.get(request).headers(headers)

def url = "${bitbucketUrl}/rest/api/latest/projects/${project}/repos/${repo}/commits/${gitCommit}/builds"
def req = Unirest.post(url.toString())
req.body(json.toString())

def response = httpRequest.asString()

response.ifFailure {
def message = 'Error: unable to get data from Bitbucket, responded with code: ' +
"'${response.getStatus()}' and message: '${response.getBody()}'."
logger.warn(message)
throw new RuntimeException(message)
}
}

@SuppressWarnings('LineLength')
void setBuildStatus(String buildUrl, String gitCommit, String state, String buildName) {
logger.debugClocked("buildstatus-${buildName}-${state}",
Expand Down

0 comments on commit 8936330

Please sign in to comment.