/** * Gets the specific property, or null if the property is not configured for * this job. */ public <T extends JobProperty> T getProperty(Class<T> clazz) { if (clazz == BuildDiscarderProperty.class && logRotator != null) { return clazz.cast(new BuildDiscarderProperty(logRotator)); } return _getProperty(clazz); }
/** * Returns the configured build discarder for this job, via {@link BuildDiscarderProperty}, or null if none. */ public synchronized BuildDiscarder getBuildDiscarder() { BuildDiscarderProperty prop = _getProperty(BuildDiscarderProperty.class); return prop != null ? prop.getStrategy() : /* settings compatibility */ logRotator; }
@SuppressWarnings("rawtypes") @Test public void configRoundTripBuildDiscarder() throws Exception { List<JobProperty> properties = Collections.<JobProperty>singletonList(new BuildDiscarderProperty(new LogRotator(1, 2, -1, 3))); // TODO structural form of LogRotator is awful; confusion between integer and string types, and failure to handle default values: new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '3', daysToKeepStr: '1', numToKeepStr: '2'))])"); StepConfigTester tester = new StepConfigTester(r); properties = tester.configRoundTrip(new JobPropertyStep(properties)).getProperties(); assertEquals(1, properties.size()); BuildDiscarderProperty bdp = getPropertyFromList(BuildDiscarderProperty.class, properties); assertNotNull(bdp); BuildDiscarder strategy = bdp.getStrategy(); assertNotNull(strategy); assertEquals(LogRotator.class, strategy.getClass()); LogRotator lr = (LogRotator) strategy; assertEquals(1, lr.getDaysToKeep()); assertEquals(2, lr.getNumToKeep()); assertEquals(-1, lr.getArtifactDaysToKeep()); assertEquals(3, lr.getArtifactNumToKeep()); }
/** * Gets all the job properties configured for this job. */ @SuppressWarnings({"unchecked", "rawtypes"}) public Map<JobPropertyDescriptor, JobProperty<? super JobT>> getProperties() { Map result = Descriptor.toMap((Iterable) properties); if (logRotator != null) { result.put(Jenkins.getActiveInstance().getDescriptorByType(BuildDiscarderProperty.DescriptorImpl.class), new BuildDiscarderProperty(logRotator)); } return result; }
/** * Returns the configured build discarder for this job, via {@link BuildDiscarderProperty}, or null if none. */ public synchronized BuildDiscarder getBuildDiscarder() { BuildDiscarderProperty prop = _getProperty(BuildDiscarderProperty.class); return prop != null ? prop.getStrategy() : /* settings compatibility */ logRotator; }
public synchronized void setBuildDiscarder(BuildDiscarder bd) throws IOException { try (BulkChange bc = new BulkChange(this)) { removeProperty(BuildDiscarderProperty.class); if (bd != null) { addProperty(new BuildDiscarderProperty(bd)); } bc.commit(); } }
@Test public void serializationJobPropsGString() throws Exception { WorkflowRun b = expect("serializationJobPropsGString") .logContains("[Pipeline] { (foo)", "hello") .logNotContains("[Pipeline] { (" + SyntheticStageNames.postBuild() + ")") .go(); WorkflowJob p = b.getParent(); BuildDiscarderProperty bdp = p.getProperty(BuildDiscarderProperty.class); assertNotNull(bdp); BuildDiscarder strategy = bdp.getStrategy(); assertNotNull(strategy); assertEquals(LogRotator.class, strategy.getClass()); LogRotator lr = (LogRotator) strategy; assertEquals(Integer.parseInt(p.getDisplayName().substring(4)), lr.getNumToKeep()); }
/** * Gets the specific property, or null if the property is not configured for * this job. */ public <T extends JobProperty> T getProperty(Class<T> clazz) { if (clazz == BuildDiscarderProperty.class && logRotator != null) { return clazz.cast(new BuildDiscarderProperty(logRotator)); } return _getProperty(clazz); }
@Test public void simpleJobProperties() throws Exception { WorkflowRun b = expect("simpleJobProperties") .logContains("[Pipeline] { (foo)", "hello") .logNotContains("[Pipeline] { (" + SyntheticStageNames.postBuild() + ")") .go(); WorkflowJob p = b.getParent(); BuildDiscarderProperty bdp = p.getProperty(BuildDiscarderProperty.class); assertNotNull(bdp); BuildDiscarder strategy = bdp.getStrategy(); assertNotNull(strategy); assertEquals(LogRotator.class, strategy.getClass()); LogRotator lr = (LogRotator) strategy; assertEquals(1, lr.getNumToKeep()); }
/** * Gets all the job properties configured for this job. */ @SuppressWarnings({"unchecked", "rawtypes"}) public Map<JobPropertyDescriptor, JobProperty<? super JobT>> getProperties() { Map result = Descriptor.toMap((Iterable) properties); if (logRotator != null) { result.put(Jenkins.getActiveInstance().getDescriptorByType(BuildDiscarderProperty.DescriptorImpl.class), new BuildDiscarderProperty(logRotator)); } return result; }
@Test public void mapCallsWithMethodCallValues() throws Exception { WorkflowRun b = expect("mapCallsWithMethodCallValues") .logContains("[Pipeline] { (foo)", "hello") .logNotContains("[Pipeline] { (" + SyntheticStageNames.postBuild() + ")") .go(); WorkflowJob p = b.getParent(); BuildDiscarderProperty bdp = p.getProperty(BuildDiscarderProperty.class); assertNotNull(bdp); BuildDiscarder strategy = bdp.getStrategy(); assertNotNull(strategy); assertEquals(LogRotator.class, strategy.getClass()); LogRotator lr = (LogRotator) strategy; assertEquals(1, lr.getNumToKeep()); }
public synchronized void setBuildDiscarder(BuildDiscarder bd) throws IOException { try (BulkChange bc = new BulkChange(this)) { removeProperty(BuildDiscarderProperty.class); if (bd != null) { addProperty(new BuildDiscarderProperty(bd)); } bc.commit(); } }
@Ignore("Properties are set before withEnv is called.") @Test public void envVarInOptions() throws Exception { WorkflowRun b = expect("envVarInOptions") .logContains("[Pipeline] { (foo)", "hello") .logNotContains("[Pipeline] { (" + SyntheticStageNames.postBuild() + ")") .go(); WorkflowJob p = b.getParent(); BuildDiscarderProperty bdp = p.getProperty(BuildDiscarderProperty.class); assertNotNull(bdp); BuildDiscarder strategy = bdp.getStrategy(); assertNotNull(strategy); assertEquals(LogRotator.class, strategy.getClass()); LogRotator lr = (LogRotator) strategy; assertEquals(1, lr.getNumToKeep()); }
@Test public void options() throws Exception { List<Describable> o = new ArrayList<>(); o.add(new BuildDiscarderProperty(new LogRotator("4", "", "", ""))); o.add(new SkipDefaultCheckout(true)); TimeoutStep timeout = new TimeoutStep(10); timeout.setUnit(TimeUnit.HOURS); o.add(timeout); OptionsDirective options = new OptionsDirective(o); assertGenerateDirective(options, "options {\n" + " buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '4', numToKeepStr: '')\n" + " skipDefaultCheckout true\n" + " timeout(time: 10, unit: 'HOURS')\n" + "}"); }
BuildDiscarder strategy = bdp.getStrategy(); assertNotNull(strategy); assertEquals(LogRotator.class, strategy.getClass());