Skip to content

Commit

Permalink
bugfix: JENKINS-36749 Saves on templates don't propagate to implement…
Browse files Browse the repository at this point in the history
…ing jobs after upgrading to 1.2
  • Loading branch information
Marc Carter committed Aug 22, 2016
1 parent 2c0d279 commit 51d0fcb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 43 deletions.
Expand Up @@ -32,7 +32,7 @@ public class TemplateImplementationProperty extends JobProperty<AbstractProject<
private final boolean syncScm;
private final boolean syncOwnership;
private final boolean syncAssignedLabel;
private final List<String> exclusions;
private List<String> exclusions; // Non-final until we drop support for upgrade from 1.1.x

public static TemplateImplementationProperty newImplementation(String templateJobName) {
return new TemplateImplementationProperty(
Expand All @@ -46,7 +46,7 @@ public static TemplateImplementationProperty newImplementation(String templateJo
public TemplateImplementationProperty(String templateJobName, List<String> exclusions, boolean syncDescription, boolean syncDisabled, boolean syncMatrixAxis, boolean syncBuildTriggers, boolean syncSecurity, boolean syncScm, boolean syncOwnership, boolean syncAssignedLabel) {
this.exclusions = exclusions;
this.templateJobName = templateJobName;
// Support for rollback to <1.3.0
// Support for rollback to <1.2.0
this.syncDescription = !exclusions.contains(DescriptionExclusion.ID);
this.syncDisabled = !exclusions.contains(DisabledExclusion.ID);
this.syncMatrixAxis = !exclusions.contains(MatrixAxisExclusion.ID);
Expand All @@ -67,6 +67,21 @@ public void setTemplateJobName(String templateJobName) {
}

public List<String> getExclusions() {
if (exclusions==null) {
LOG.info("Upgrading from earlier EZ Templates installation");
ImmutableList.Builder<String> list = ImmutableList.builder();
list.add(EzTemplatesExclusion.ID);
list.add(JobParametersExclusion.ID);
if (!syncDescription) list.add(DescriptionExclusion.ID);
if (!syncDisabled) list.add(DisabledExclusion.ID);
if (!syncMatrixAxis) list.add(MatrixAxisExclusion.ID);
if (!syncBuildTriggers) list.add(TriggersExclusion.ID);
if (!syncSecurity) list.add(Exclusions.MATRIX_SECURITY_ID);
if (!syncScm) list.add(ScmExclusion.ID);
if (!syncOwnership) list.add(Exclusions.OWNERSHIP_ID);
if (!syncAssignedLabel) list.add(AssignedLabelExclusion.ID);
exclusions = list.build();
}
return exclusions;
}

Expand Down Expand Up @@ -160,30 +175,6 @@ public List<String> getDefaultExclusions() {
return Exclusions.DEFAULT;
}

public List<String> migrateExclusions(
boolean syncDescription,
boolean syncDisabled,
boolean syncMatrixAxis,
boolean syncBuildTriggers,
boolean syncSecurity,
boolean syncScm,
boolean syncOwnership,
boolean syncAssignedLabel) {
LOG.info("Upgrading from earlier EZ Templates installation");
ImmutableList.Builder<String> list = ImmutableList.builder();
list.add(EzTemplatesExclusion.ID);
list.add(JobParametersExclusion.ID);
if (!syncDescription) list.add(DescriptionExclusion.ID);
if (!syncDisabled) list.add(DisabledExclusion.ID);
if (!syncMatrixAxis) list.add(MatrixAxisExclusion.ID);
if (!syncBuildTriggers) list.add(TriggersExclusion.ID);
if (!syncSecurity) list.add(Exclusions.MATRIX_SECURITY_ID);
if (!syncScm) list.add(ScmExclusion.ID);
if (!syncOwnership) list.add(Exclusions.OWNERSHIP_ID);
if (!syncAssignedLabel) list.add(AssignedLabelExclusion.ID);
return list.build();
}

}
}

Expand Up @@ -61,16 +61,16 @@ public static void handleTemplateCopied(AbstractProject copy, AbstractProject or
public static void handleTemplateImplementationSaved(AbstractProject implementationProject, TemplateImplementationProperty property) throws IOException {

if (property.getTemplateJobName().equals("null")) {
LOG.warning(String.format("Implementation [%s] was saved. No template selected.", implementationProject.getFullDisplayName()));
LOG.warning(String.format("Implementation [%s] but has no template selected.", implementationProject.getFullDisplayName()));
return;
}
LOG.info(String.format("Implementation [%s] was saved. Syncing with [%s].", implementationProject.getFullDisplayName(), property.getTemplateJobName()));

LOG.info(String.format("Implementation [%s] syncing with [%s].", implementationProject.getFullDisplayName(), property.getTemplateJobName()));

AbstractProject templateProject = property.findTemplate();
if (templateProject == null) {
// If the template can't be found, then it's probably a bug
throw new IllegalStateException(String.format("Cannot find template [%s] used by job [%s]", property.getTemplateJobName(), implementationProject.getFullDisplayName()));
throw new IllegalStateException(String.format("Cannot find template [%s] used by implementation [%s]", property.getTemplateJobName(), implementationProject.getFullDisplayName()));
}

Collection<Exclusion> exclusions = Exclusions.configuredExclusions(property);
Expand Down
Expand Up @@ -19,19 +19,7 @@
<f:advanced>
<f:entry>
Features exempted from templating:
<j:choose>
<!-- post-migration, replace with inline -->
<!--<j:set var="selections" value="${instance==null?descriptor.defaultExclusions:instance.exclusions}"/>-->
<j:when test="${instance==null}">
<j:set var="selections" value="${descriptor.defaultExclusions}"/>
</j:when>
<j:when test="${instance.exclusions!=null}">
<j:set var="selections" value="${instance.exclusions}"/>
</j:when>
<j:otherwise>
<j:set var="selections" value="${descriptor.migrateExclusions(instance.syncDescription,instance.syncDisabled,instance.syncMatrixAxis,instance.syncBuildTriggers,instance.syncSecurity,instance.syncScm,instance.syncOwnership,instance.syncAssignedLabel)}"/>
</j:otherwise>
</j:choose>
<j:set var="selections" value="${instance==null?descriptor.defaultExclusions:instance.exclusions}"/>
<f:invisibleEntry>
<!-- force ez-templates into the exclusion list -->
<div style="display: none;">
Expand Down

0 comments on commit 51d0fcb

Please sign in to comment.