Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


### Fixed
* Add some logs for the updateStatusIssue call to jira plugin ([#1212](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1212))
* Remove missing tests count ([#1213](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1213))
* Fix Tailor deployment drifts for D, Q envs ([#1055](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1055))

Expand Down
7 changes: 4 additions & 3 deletions src/org/ods/orchestration/InitStage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class InitStage extends Stage {
)

if (project.services?.jira) {
addJiraToRegistry(registry)
addJiraToRegistry(registry, logger)
}

registry.add(NexusService, NexusService.newFromEnv(script.env, steps,
Expand Down Expand Up @@ -442,7 +442,7 @@ class InitStage extends Stage {
registry.add(JiraUseCase, jiraUseCase)
}

private void addJiraToRegistry(registry) {
private void addJiraToRegistry(registry, Logger logger) {
script.withCredentials(
[script.usernamePassword(
credentialsId: project.services.jira.credentials.id,
Expand All @@ -454,7 +454,8 @@ class InitStage extends Stage {
new JiraService(
script.env.JIRA_URL,
script.env.JIRA_USERNAME,
script.env.JIRA_PASSWORD
script.env.JIRA_PASSWORD,
logger
)
)

Expand Down
48 changes: 35 additions & 13 deletions src/org/ods/orchestration/service/JiraService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package org.ods.orchestration.service
@Grab(group="com.konghq", module="unirest-java", version="2.4.03", classifier="standalone")

import com.cloudbees.groovy.cps.NonCPS

import groovy.json.JsonOutput
import groovy.json.JsonSlurperClassic
import org.ods.orchestration.util.StringCleanup

import kong.unirest.Unirest

import org.apache.http.client.utils.URIBuilder
import org.ods.orchestration.util.StringCleanup
import org.ods.util.ILogger

@SuppressWarnings(['LineLength', 'ParameterName'])
class JiraService {
Expand All @@ -24,7 +22,11 @@ class JiraService {
String username
String password

JiraService(String baseURL, String username, String password) {
private final ILogger logger

JiraService(String baseURL, String username, String password, ILogger logger) {
this.logger = logger

if (!baseURL?.trim()) {
throw new IllegalArgumentException('Error: unable to connect to Jira. \'baseURL\' is undefined.')
}
Expand Down Expand Up @@ -634,8 +636,15 @@ class JiraService {
return new JsonSlurperClassic().parseText(StringCleanup.removeCharacters(response.getBody(), CHARACTER_REMOVEABLE))
}


@NonCPS
void updateReleaseStatusIssue(String projectKey, String version, Map fields) {
try {
logger.debug "-> Updating release status issue for project ${projectKey}, version ${version} with fields ${fields}"
} catch (Exception e) {
logger.error(e.getMessage(), e)
}

if (!projectKey?.trim()) {
throw new IllegalArgumentException('Error: Unable to update the release status issue: \'projectKey\' is undefined')
}
Expand All @@ -646,15 +655,26 @@ class JiraService {
throw new IllegalArgumentException('Error: Unable to update the release status issue: no data given for updating')
}

def response = Unirest.post("${this.baseURL}/rest/platform/1.1/productreleases/{projectKey}/{version}/status")
.routeParam("projectKey", projectKey.toUpperCase())
.routeParam("version", version)
.basicAuth(this.username, this.password)
.header("Accept", "application/json")
.header('Content-Type', 'application/json')
.body(JsonOutput.toJson(fields)).asString()
def response = null
try {
response = Unirest.post("${this.baseURL}/rest/platform/1.1/productreleases/{projectKey}/{version}/status")
.routeParam("projectKey", projectKey.toUpperCase())
.routeParam("version", version)
.basicAuth(this.username, this.password)
.header("Accept", "application/json")
.header('Content-Type', 'application/json')
.body(JsonOutput.toJson(fields)).asString()
} catch (Exception e) {
logger.error(e.getMessage(), e)
}

response.ifFailure {
try {
logger.debug "-> Update release status issue response for project ${projectKey}, response ${response}"
} catch (Exception e) {
logger.error(e.getMessage(), e)
}

response?.ifFailure {
def message = 'Error: unable to update release status issue. Jira responded with code: ' +
"'${response.getStatus()}' and message: '${response.getBody()}'."

Expand All @@ -669,6 +689,8 @@ class JiraService {

@NonCPS
void updateBuildNumber(String projectKey, String version, String buildNumber) {
logger.debug "-> Updating build number for project ${projectKey}, version ${version} and buildNumber ${buildNumber}"

if (!projectKey?.trim()) {
throw new IllegalArgumentException('Error: Unable to update the build number: \'projectKey\' is undefined')
}
Expand Down
5 changes: 3 additions & 2 deletions src/org/ods/orchestration/service/JiraZephyrService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import groovy.json.JsonOutput
import groovy.json.JsonSlurperClassic

import kong.unirest.Unirest
import org.ods.util.ILogger

@SuppressWarnings('LineLength')
class JiraZephyrService extends JiraService {
Expand All @@ -19,8 +20,8 @@ class JiraZephyrService extends JiraService {
static final String BLOCKED = "4"
}

JiraZephyrService(String baseURL, String username, String password) {
super(baseURL, username, password)
JiraZephyrService(String baseURL, String username, String password, ILogger logger) {
super(baseURL, username, password, logger)
}

@NonCPS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package org.ods.core.test.jira

import groovy.util.logging.Slf4j
import org.ods.orchestration.service.JiraService
import org.ods.util.ILogger

@Slf4j
class JiraServiceForWireMock extends JiraService {
JiraServiceForWireMock(String baseURL, String username, String password) {
super(baseURL, username, password)
JiraServiceForWireMock(String baseURL, String username, String password, ILogger logger) {
super(baseURL, username, password, logger)
}

@Override
Expand Down
18 changes: 9 additions & 9 deletions test/groovy/org/ods/orchestration/service/JiraServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,48 @@ import util.*
class JiraServiceSpec extends SpecHelper {

JiraService createService(int port, String username, String password) {
return new JiraService("http://localhost:${port}", username, password)
return new JiraService("http://localhost:${port}", username, password, null)
}

def "create with invalid baseURL"() {
when:
new JiraService(null, "username", "password")
new JiraService(null, "username", "password", null)

then:
def e = thrown(IllegalArgumentException)
e.message == "Error: unable to connect to Jira. 'baseURL' is undefined."

when:
new JiraService(" ", "username", "password")
new JiraService(" ", "username", "password", null)

then:
e = thrown(IllegalArgumentException)
e.message == "Error: unable to connect to Jira. 'baseURL' is undefined."

when:
new JiraService("invalid URL", "username", "password")
new JiraService("invalid URL", "username", "password", null)

then:
e = thrown(IllegalArgumentException)
e.message == "Error: unable to connect to Jira. 'invalid URL' is not a valid URI."

when:
def jira = new JiraService("http://localhostwithtrailing/", "user", "password")
def jira = new JiraService("http://localhostwithtrailing/", "user", "password", null)

then:
jira.baseURL.toString() == "http://localhostwithtrailing"
}

def "create with invalid username"() {
when:
new JiraService("http://localhost", null, "password")
new JiraService("http://localhost", null, "password", null)

then:
def e = thrown(IllegalArgumentException)
e.message == "Error: unable to connect to Jira. 'username' is undefined."

when:
new JiraService("http://localhost", " ", "password")
new JiraService("http://localhost", " ", "password", null)

then:
e = thrown(IllegalArgumentException)
Expand All @@ -59,14 +59,14 @@ class JiraServiceSpec extends SpecHelper {

def "create with invalid password"() {
when:
new JiraService("http://localhost", "username", null)
new JiraService("http://localhost", "username", null, null)

then:
def e = thrown(IllegalArgumentException)
e.message == "Error: unable to connect to Jira. 'password' is undefined."

when:
new JiraService("http://localhost", "username", " ")
new JiraService("http://localhost", "username", " ", null)

then:
e = thrown(IllegalArgumentException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import util.*
class JiraZephyrServiceSpec extends SpecHelper {

JiraZephyrService createService(int port, String username, String password) {
return new JiraZephyrService("http://localhost:${port}", username, password)
return new JiraZephyrService("http://localhost:${port}", username, password, null)
}

Map createTestExecutionForIssueRequestData(Map mixins = [:]) {
Expand Down Expand Up @@ -650,15 +650,15 @@ class JiraZephyrServiceSpec extends SpecHelper {
body: JsonOutput.toJson([
recordsCount: "2",
"-1": [
versionName: "0.1",
projectKey: "DEMO",
versionId:"456",
versionName: "0.1",
projectKey: "DEMO",
versionId:"456",
name: "Ad hoc"
],
],
"7": [
versionName: "0.1",
projectKey: "DEMO",
versionId: "456",
versionName: "0.1",
projectKey: "DEMO",
versionId: "456",
name: "Cycle name"
]
])
Expand Down