Skip to content

Commit ff4ce52

Browse files
committed
Add optional ID to the pod template step class such that it can be supplied by dynamic groovy and then applied if present in the step execution, thus leaving functionality unchanged for existing use cases such as manually configuring pod templates in a Jenkins UI.
1 parent 4818b92 commit ff4ce52

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public class PodTemplateStep extends Step implements Serializable {
5454
@CheckForNull
5555
private String name;
5656

57+
private String id;
58+
5759
@CheckForNull
5860
private String namespace;
5961

@@ -118,11 +120,20 @@ public void setLabel(@CheckForNull String label) {
118120
this.label = Util.fixEmpty(label);
119121
}
120122

123+
@DataBoundSetter
124+
public void setId(String id) {
125+
this.id = Util.fixEmpty(id);
126+
}
127+
121128
@CheckForNull
122129
public String getName() {
123130
return name;
124131
}
125132

133+
public String getId() {
134+
return id;
135+
}
136+
126137
@DataBoundSetter
127138
public void setName(@CheckForNull String name) {
128139
this.name = Util.fixEmpty(name);

src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStepExecution.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ public boolean start() throws Exception {
8484
String name = String.format(NAME_FORMAT, stepName, randString);
8585
String namespace = checkNamespace(cloud, podTemplateContext);
8686

87-
newTemplate = new PodTemplate();
87+
if (step.getId() != null) {
88+
newTemplate = new PodTemplate(step.getId());
89+
} else {
90+
newTemplate = new PodTemplate();
91+
}
92+
8893
newTemplate.setName(name);
8994
newTemplate.setNamespace(namespace);
9095

0 commit comments

Comments
 (0)