Skip to content
Permalink
Browse files

JENKINS-46482 Use ParametersAction instead of EnvironmentContributing…

…Action.

Apparently EnvironmentContributingAction is not working in a pipeline job and the fix requires Jenkins core 2.76+. See JENKINS-29537.
  • Loading branch information
ceilfors committed Sep 8, 2017
1 parent f6120fe commit 4cf64c12f9fcbe00d54d5fcb7f8dfe9926e35f57
@@ -10,18 +10,18 @@ import com.ceilfors.jenkins.plugins.jiratrigger.webhook.JiraWebhook
import hudson.model.AbstractBuild
import hudson.model.AbstractProject
import hudson.model.FreeStyleProject
import hudson.model.ParametersAction
import hudson.model.Queue
import hudson.model.TaskListener
import hudson.model.StringParameterValue
import jenkins.model.GlobalConfiguration
import org.jvnet.hudson.test.JenkinsRule

import static org.hamcrest.Matchers.containsInAnyOrder
import static org.hamcrest.Matchers.empty
import static org.hamcrest.Matchers.equalTo
import static org.hamcrest.Matchers.hasEntry
import static org.hamcrest.Matchers.is
import static org.hamcrest.Matchers.not
import static org.junit.Assert.assertThat

/**
* @author ceilfors
*/
@@ -57,9 +57,9 @@ class JenkinsRunner extends JenkinsRule {
assertThat('Last build scheduled does not match the job name asserted', job.fullName, is(jobName))
if (parameterMap) {
AbstractBuild build = getScheduledBuild(job)
parameterMap.each { key, value ->
assertThat(build.getEnvironment(TaskListener.NULL), hasEntry(key, value))
}
def parametersAction = build.getAction(ParametersAction)
assertThat(parametersAction.parameters,
containsInAnyOrder(*parameterMap.collect { key, value -> new StringParameterValue(key, value) }))
}
}

@@ -2,43 +2,17 @@ package com.ceilfors.jenkins.plugins.jiratrigger

import com.atlassian.jira.rest.client.api.domain.Issue
import com.ceilfors.jenkins.plugins.jiratrigger.parameter.ParameterMapping
import hudson.EnvVars
import hudson.model.AbstractBuild
import hudson.model.EnvironmentContributingAction
import hudson.model.ParametersAction
import hudson.model.StringParameterValue

/**
* @author ceilfors
*/
class ParameterMappingAction implements EnvironmentContributingAction {

private final Issue issue
private final List<ParameterMapping> parameterMappings
class ParameterMappingAction extends ParametersAction {

ParameterMappingAction(Issue issue, List<ParameterMapping> parameterMappings) {
this.issue = issue
this.parameterMappings = parameterMappings
}

@Override
void buildEnvVars(AbstractBuild<?, ?> build, EnvVars env) {
parameterMappings.each { parameterMapping ->
env.put(parameterMapping.jenkinsParameter,
parameterMapping.parameterResolver.resolve(issue))
}
}

@Override
String getIconFileName() {
null
}

@Override
String getDisplayName() {
null
}

@Override
String getUrlName() {
null
super(parameterMappings.collect { p ->
new StringParameterValue(p.jenkinsParameter, p.parameterResolver.resolve(issue))
}, parameterMappings*.jenkinsParameter)
}
}

0 comments on commit 4cf64c1

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