@Override public boolean isProject(Item item) { return item instanceof WorkflowJob && ((WorkflowJob) item).getProperty(BranchJobProperty.class) != null; }
@Override public boolean isProject(Item item) { return item instanceof WorkflowJob && ((WorkflowJob) item).getProperty(BranchJobProperty.class) != null; }
public PipelineTriggersJobProperty getTriggersJobProperty() { PipelineTriggersJobProperty triggerProp = getProperty(PipelineTriggersJobProperty.class); if (triggerProp == null) { triggerProp = new PipelineTriggersJobProperty(new ArrayList<Trigger>()); } return triggerProp; }
@Exported @Override public boolean isConcurrentBuild() { return getProperty(DisableConcurrentBuildsJobProperty.class) == null; }
@Override public Branch getBranch(WorkflowJob project) { return project.getProperty(BranchJobProperty.class).getBranch(); }
@Override public Branch getBranch(WorkflowJob project) { return project.getProperty(BranchJobProperty.class).getBranch(); }
public void upsertItem(Item item) { if (item instanceof WorkflowJob) { WorkflowJob job = (WorkflowJob) item; if (job.getProperty(BuildConfigProjectProperty.class) != null && StringUtils.isNotBlank(job.getProperty(BuildConfigProjectProperty.class).getNamespace()) && StringUtils.isNotBlank(job.getProperty(BuildConfigProjectProperty.class).getName())) { logger.info("Updated WorkflowJob " + job.getDisplayName() + " replicating changes to OpenShift"); upsertBuildConfigForJob(job); } } }
@Override public <T> String getText(Message<T> text, T context) { if (text == AbstractItem.PRONOUN && context instanceof WorkflowJob) { WorkflowJob job = (WorkflowJob) context; BranchJobProperty property = job.getProperty(BranchJobProperty.class); if (property != null) { return property.getBranch().getHead().getPronoun(); } } return null; } }
@Override public <T> String getText(Message<T> text, T context) { if (text == AbstractItem.PRONOUN && context instanceof WorkflowJob) { WorkflowJob job = (WorkflowJob) context; BranchJobProperty property = job.getProperty(BranchJobProperty.class); if (property != null) { return property.getBranch().getHead().getPronoun(); } } return null; } }
@Override public WorkflowJob setBranch(WorkflowJob project, Branch branch) { project.setDefinition(createDefinition()); BranchJobProperty property = project.getProperty(BranchJobProperty.class); try { if (property == null) { project.addProperty(new BranchJobProperty(branch)); } else { // TODO may add equality check if https://github.com/jenkinsci/branch-api-plugin/pull/36 or equivalent is implemented property.setBranch(branch); project.save(); } } catch (IOException x) { LOGGER.log(Level.WARNING, null, x); } return project; }
@Issue("JENKINS-44149") @Test public void triggersRemoved() throws Exception { WorkflowRun b = getAndStartNonRepoBuild("simpleTriggers"); j.assertBuildStatusSuccess(j.waitForCompletion(b)); WorkflowJob job = b.getParent(); PipelineTriggersJobProperty triggersJobProperty = job.getProperty(PipelineTriggersJobProperty.class); assertNotNull(triggersJobProperty); assertEquals(1, triggersJobProperty.getTriggers().size()); job.setDefinition(new CpsFlowDefinition(pipelineSourceFromResources("propsTriggersParamsRemoved"), true)); j.buildAndAssertSuccess(job); assertNull(job.getProperty(PipelineTriggersJobProperty.class)); }
@Issue("JENKINS-44149") @Test public void propsRemoved() throws Exception { WorkflowRun b = getAndStartNonRepoBuild("simpleJobProperties"); j.assertBuildStatusSuccess(j.waitForCompletion(b)); WorkflowJob job = b.getParent(); assertNotNull(job.getProperty(BuildDiscarderProperty.class)); job.setDefinition(new CpsFlowDefinition(pipelineSourceFromResources("propsTriggersParamsRemoved"), true)); j.buildAndAssertSuccess(job); assertNull(job.getProperty(BuildDiscarderProperty.class)); }
@Issue("JENKINS-44149") @Test public void paramsRemoved() throws Exception { WorkflowRun b = getAndStartNonRepoBuild("simpleParameters"); j.assertBuildStatusSuccess(j.waitForCompletion(b)); WorkflowJob job = b.getParent(); ParametersDefinitionProperty paramProp = job.getProperty(ParametersDefinitionProperty.class); assertNotNull(paramProp); assertEquals(1, paramProp.getParameterDefinitions().size()); job.setDefinition(new CpsFlowDefinition(pipelineSourceFromResources("propsTriggersParamsRemoved"), true)); j.buildAndAssertSuccess(job); assertNull(job.getProperty(ParametersDefinitionProperty.class)); }
@Test public void simpleParameters() throws Exception { WorkflowRun b = expect("simpleParameters") .logContains("[Pipeline] { (foo)", "hello") .logNotContains("[Pipeline] { (" + SyntheticStageNames.postBuild() + ")") .go(); WorkflowJob p = b.getParent(); ParametersDefinitionProperty pdp = p.getProperty(ParametersDefinitionProperty.class); assertNotNull(pdp); assertEquals(1, pdp.getParameterDefinitions().size()); assertEquals(BooleanParameterDefinition.class, pdp.getParameterDefinitions().get(0).getClass()); BooleanParameterDefinition bpd = (BooleanParameterDefinition) pdp.getParameterDefinitions().get(0); assertEquals("flag", bpd.getName()); assertTrue(bpd.isDefaultValue()); }
@Ignore("jira-step pulls in dependencies that break form submission, so...ignore this test. We know it's fine now anyway.") @Issue("JENKINS-48115") @Test public void disableConcurrentBuilds() throws Exception { WorkflowRun b = expect("disableConcurrentBuilds") .go(); WorkflowJob p = b.getParent(); DisableConcurrentBuildsJobProperty prop = p.getProperty(DisableConcurrentBuildsJobProperty.class); assertNotNull(prop); }
@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()); }
@Test public void serializationParametersGString() throws Exception { WorkflowRun b = expect("serializationParametersGString") .logContains("[Pipeline] { (foo)", "hello") .logNotContains("[Pipeline] { (" + SyntheticStageNames.postBuild() + ")") .go(); WorkflowJob p = b.getParent(); ParametersDefinitionProperty pdp = p.getProperty(ParametersDefinitionProperty.class); assertNotNull(pdp); assertEquals(1, pdp.getParameterDefinitions().size()); assertEquals(BooleanParameterDefinition.class, pdp.getParameterDefinitions().get(0).getClass()); BooleanParameterDefinition bpd = (BooleanParameterDefinition) pdp.getParameterDefinitions().get(0); assertEquals(p.getDisplayName(), bpd.getName()); assertTrue(bpd.isDefaultValue()); }
@Ignore("Parameters are set before withEnv is called.") @Test public void envVarInParameters() throws Exception { WorkflowRun b = expect("envVarInParameters") .logContains("[Pipeline] { (foo)", "hello") .logNotContains("[Pipeline] { (" + SyntheticStageNames.postBuild() + ")") .go(); WorkflowJob p = b.getParent(); ParametersDefinitionProperty pdp = p.getProperty(ParametersDefinitionProperty.class); assertNotNull(pdp); assertEquals(1, pdp.getParameterDefinitions().size()); assertEquals(BooleanParameterDefinition.class, pdp.getParameterDefinitions().get(0).getClass()); BooleanParameterDefinition bpd = (BooleanParameterDefinition) pdp.getParameterDefinitions().get(0); assertEquals("flag", bpd.getName()); assertTrue(bpd.isDefaultValue()); }
@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()); }
@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()); }