Skip to content

Commit

Permalink
[JENKINS-58574] Fix inheritance of showRawYaml (#556)
Browse files Browse the repository at this point in the history
[JENKINS-58574] Fix inheritance of showRawYaml
  • Loading branch information
Vlatombe committed Jul 29, 2019
2 parents 9ecd736 + 7ce52eb commit a9df9a1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
Expand Up @@ -766,8 +766,12 @@ public String getDescriptionForLogging() {
getContainersDescriptionForLogging());
}

boolean isShowRawYamlSet() {
return showRawYaml != null;
}

public boolean isShowRawYaml() {
return showRawYaml == null ? true : showRawYaml.booleanValue();
return isShowRawYamlSet() ? showRawYaml.booleanValue() : true;
}

@DataBoundSetter
Expand Down
Expand Up @@ -374,6 +374,7 @@ public static PodTemplate combine(PodTemplate parent, PodTemplate template) {
podTemplate.setCustomWorkspaceVolumeEnabled(template.isCustomWorkspaceVolumeEnabled() ?
template.isCustomWorkspaceVolumeEnabled() : parent.isCustomWorkspaceVolumeEnabled());
podTemplate.setPodRetention(template.getPodRetention());
podTemplate.setShowRawYaml(template.isShowRawYamlSet() ? template.isShowRawYaml() : parent.isShowRawYaml());

List<String> yamls = new ArrayList<>(parent.getYamls());
yamls.addAll(template.getYamls());
Expand Down
Expand Up @@ -281,8 +281,12 @@ public void setPodRetention(PodRetention podRetention) {
this.podRetention = podRetention;
}

boolean isShowRawYamlSet() {
return showRawYaml != null;
}

public boolean isShowRawYaml() {
return showRawYaml == null ? true : showRawYaml.booleanValue();
return isShowRawYamlSet() ? showRawYaml.booleanValue() : true;
}

@DataBoundSetter
Expand Down
Expand Up @@ -120,7 +120,9 @@ public boolean start() throws Exception {
newTemplate.setImagePullSecrets(
step.getImagePullSecrets().stream().map(x -> new PodImagePullSecret(x)).collect(toList()));
newTemplate.setYaml(step.getYaml());
newTemplate.setShowRawYaml(step.isShowRawYaml());
if (step.isShowRawYamlSet()) {
newTemplate.setShowRawYaml(step.isShowRawYaml());
}
newTemplate.setPodRetention(step.getPodRetention());

if(step.getActiveDeadlineSeconds() != 0) {
Expand Down
Expand Up @@ -412,6 +412,13 @@ public void runInPodWithShowRawYamlFalse() throws Exception {
r.assertLogNotContains("value: \"container-env-var-value\"", b);
}

@Issue("JENKINS-58574")
@Test
public void showRawYamlFalseInherited() throws Exception {
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogNotContains("value: \"container-env-var-value\"", b);
}

@Test
@Issue("JENKINS-58405")
public void overrideYaml() throws Exception {
Expand Down
@@ -0,0 +1,26 @@
podTemplate(showRawYaml: false) { podTemplate(yaml: '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: busybox
image: busybox
command:
- cat
tty: true
env:
- name: CONTAINER_ENV_VAR
value: container-env-var-value
'''
)
{
node(POD_LABEL) {
stage('Run') {
container('busybox') {
sh '''
echo "anything"
'''
}
}
}
} }

0 comments on commit a9df9a1

Please sign in to comment.