Skip to content

Commit

Permalink
Merge pull request #666 from Vlatombe/JENKINS-60537
Browse files Browse the repository at this point in the history
[JENKINS-60537] Fix support of pod templates with multiple labels
  • Loading branch information
Vlatombe authored Dec 19, 2019
2 parents 922ecf3 + 89d6282 commit c71974e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,7 @@ public Set<LabelAtom> getLabelSet() {
}

public Map<String, String> getLabelsMap() {
Set<LabelAtom> labelSet = getLabelSet();
ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String> builder();
if (!labelSet.isEmpty()) {
for (LabelAtom label : labelSet) {
builder.put("jenkins/label",label == null ? DEFAULT_ID : label.getName());
}
}
return builder.build();
return ImmutableMap.of("jenkins/label", label == null ? DEFAULT_ID : label);
}

@DataBoundSetter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.csanchez.jenkins.plugins.kubernetes;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

import static org.junit.Assert.assertEquals;

public class PodTemplateJenkinsTest {
@Rule
public JenkinsRule j = new JenkinsRule();

@Test
@Issue("JENKINS-60537")
public void singleLabel() {
PodTemplate podTemplate = new PodTemplate();
podTemplate.setLabel("foo");
assertEquals("foo" , podTemplate.getLabelsMap().get("jenkins/label"));
}

@Test
@Issue("JENKINS-60537")
public void multiLabel() {
PodTemplate podTemplate = new PodTemplate();
podTemplate.setLabel("foo bar");
assertEquals("foo bar", podTemplate.getLabelsMap().get("jenkins/label"));
}
}

0 comments on commit c71974e

Please sign in to comment.