Skip to content
Permalink
Browse files

JENKINS-46482 Return String instead of StringParameterValue.

  • Loading branch information
ceilfors committed Sep 1, 2017
1 parent 08d6145 commit 25354815391995a79d4f939f7d68760ee1551351
@@ -23,7 +23,7 @@ class ParameterMappingAction implements EnvironmentContributingAction {
void buildEnvVars(AbstractBuild<?, ?> build, EnvVars env) {
parameterMappings.each { parameterMapping ->
env.put(parameterMapping.jenkinsParameter,
parameterMapping.parameterResolver.resolve(issue).value as String)
parameterMapping.parameterResolver.resolve(issue))
}
}

@@ -3,7 +3,6 @@ package com.ceilfors.jenkins.plugins.jiratrigger.parameter
import com.atlassian.jira.rest.client.api.domain.Issue
import com.atlassian.jira.rest.client.api.domain.IssueField
import com.ceilfors.jenkins.plugins.jiratrigger.JiraTriggerException
import hudson.model.StringParameterValue
import org.codehaus.jettison.json.JSONArray
import org.codehaus.jettison.json.JSONObject

@@ -19,11 +18,11 @@ class CustomFieldParameterResolver implements ParameterResolver {
this.customFieldParameterMapping = customFieldParameterMapping
}

StringParameterValue resolve(Issue issue) {
String resolve(Issue issue) {
String customFieldId = "customfield_${customFieldParameterMapping.customFieldId}"
IssueField field = issue.fields.toList().find { f -> f.id == customFieldId }
if (field) {
new StringParameterValue(customFieldParameterMapping.jenkinsParameter, extractValue(field))
extractValue(field)
} else {
throw new JiraTriggerException(ParameterErrorCode.FAILED_TO_RESOLVE)
.add('customFieldId', customFieldId)
@@ -2,7 +2,6 @@ package com.ceilfors.jenkins.plugins.jiratrigger.parameter

import com.atlassian.jira.rest.client.api.domain.Issue
import com.ceilfors.jenkins.plugins.jiratrigger.JiraTriggerException
import hudson.model.StringParameterValue

/**
* @author ceilfors
@@ -15,9 +14,8 @@ class IssueAttributePathParameterResolver implements ParameterResolver {
this.issueAttributePathParameterMapping = issueAttributePathParameterMapping
}

StringParameterValue resolve(Issue issue) {
String attributeValue = resolveProperty(issue.properties, issueAttributePathParameterMapping.issueAttributePath)
new StringParameterValue(issueAttributePathParameterMapping.jenkinsParameter, attributeValue)
String resolve(Issue issue) {
resolveProperty(issue.properties, issueAttributePathParameterMapping.issueAttributePath)
}

/**
@@ -1,14 +1,12 @@
package com.ceilfors.jenkins.plugins.jiratrigger.parameter

import com.atlassian.jira.rest.client.api.domain.Issue
import hudson.model.StringParameterValue

/**
* Responsible for providing a parameter value for Jenkins by digesting JIRA information.
*
* @author ceilfors
*/
interface ParameterResolver {

StringParameterValue resolve(Issue issue)
String resolve(Issue issue)
}
@@ -3,7 +3,6 @@ package com.ceilfors.jenkins.plugins.jiratrigger.parameter
import com.atlassian.jira.rest.client.api.domain.Issue
import com.ceilfors.jenkins.plugins.jiratrigger.JiraTriggerException
import com.ceilfors.jenkins.plugins.jiratrigger.webhook.WebhookChangelogEventJsonParser
import hudson.model.StringParameterValue
import org.codehaus.jettison.json.JSONObject
import spock.lang.Specification
import spock.lang.Unroll
@@ -24,12 +23,10 @@ class CustomFieldParameterResolverTest extends Specification {
when:
CustomFieldParameterMapping mapping = new CustomFieldParameterMapping('parameter', customFieldId)
CustomFieldParameterResolver subject = new CustomFieldParameterResolver(mapping)
StringParameterValue result = subject.resolve(createIssueFromFile('single_value_custom_field'))
String result = subject.resolve(createIssueFromFile('single_value_custom_field'))

then:
result != null
result.value == attributeValue
result.name == 'parameter'
result == attributeValue

where:
customFieldType | customFieldId | attributeValue
@@ -54,12 +51,10 @@ class CustomFieldParameterResolverTest extends Specification {
when:
CustomFieldParameterMapping mapping = new CustomFieldParameterMapping('parameter', customFieldId)
CustomFieldParameterResolver subject = new CustomFieldParameterResolver(mapping)
StringParameterValue result = subject.resolve(createIssueFromFile('multi_value_custom_field'))
String result = subject.resolve(createIssueFromFile('multi_value_custom_field'))

then:
result != null
result.value == attributeValue
result.name == 'parameter'
result == attributeValue

where:
customFieldType | customFieldId | attributeValue
@@ -75,12 +70,10 @@ class CustomFieldParameterResolverTest extends Specification {
when:
CustomFieldParameterMapping mapping = new CustomFieldParameterMapping('parameter', customFieldId)
CustomFieldParameterResolver subject = new CustomFieldParameterResolver(mapping)
StringParameterValue result = subject.resolve(createIssueFromFile('empty_custom_field'))
String result = subject.resolve(createIssueFromFile('empty_custom_field'))

then:
result != null
result.value == attributeValue
result.name == 'parameter'
result == attributeValue

where:
customFieldType | customFieldId | attributeValue
@@ -3,7 +3,6 @@ package com.ceilfors.jenkins.plugins.jiratrigger.parameter
import com.atlassian.jira.rest.client.api.domain.Issue
import com.atlassian.jira.rest.client.internal.json.IssueJsonParser
import com.ceilfors.jenkins.plugins.jiratrigger.JiraTriggerException
import hudson.model.StringParameterValue
import org.codehaus.jettison.json.JSONObject
import spock.lang.Specification
import spock.lang.Unroll
@@ -25,12 +24,10 @@ class IssueAttributePathParameterResolverTest extends Specification {
IssueAttributePathParameterResolver resolver = new IssueAttributePathParameterResolver(mapping)

when:
StringParameterValue result = resolver.resolve(createIssueFromFile('TEST-136'))
String result = resolver.resolve(createIssueFromFile('TEST-136'))

then:
result != null
result.value == attributeValue
result.name == 'parameter'
result == attributeValue

where:
attributePath | attributeValue
@@ -49,7 +46,6 @@ class IssueAttributePathParameterResolverTest extends Specification {
IssueAttributePathParameterResolver resolver = new IssueAttributePathParameterResolver(mapping)

when:

resolver.resolve(createIssueFromFile('TEST-136'))

then:

0 comments on commit 2535481

Please sign in to comment.
You can’t perform that action at this time.