public PipelineTriggersJobProperty getTriggersJobProperty() { PipelineTriggersJobProperty triggerProp = getProperty(PipelineTriggersJobProperty.class); if (triggerProp == null) { triggerProp = new PipelineTriggersJobProperty(new ArrayList<Trigger>()); } return triggerProp; }
PipelineTriggersJobProperty thisProp = new PipelineTriggersJobProperty(new ArrayList<Trigger>(trigList.toList()));
public void setTriggers(List<Trigger<?>> inputTriggers) throws IOException { triggers = null; BulkChange bc = new BulkChange(this); try { PipelineTriggersJobProperty originalProp = getTriggersJobProperty(); removeProperty(PipelineTriggersJobProperty.class); PipelineTriggersJobProperty triggerProp = new PipelineTriggersJobProperty(null); triggerProp.setTriggers(inputTriggers); addProperty(triggerProp); bc.commit(); originalProp.stopTriggers(); // No longer need to start triggers here - that's done by when we add the property. } finally { bc.abort(); } }
@Issue("JENKINS-37477") @Test public void configRoundTripTrigger() throws Exception { List<JobProperty> properties = Collections.<JobProperty>singletonList(new PipelineTriggersJobProperty(Collections.<Trigger>singletonList(new TimerTrigger("@daily")))); String snippetJson = "{'propertiesMap': {\n" + " 'stapler-class-bag': 'true',\n" + " 'org-jenkinsci-plugins-workflow-job-properties-PipelineTriggersJobProperty': {'triggers': {\n" + " 'stapler-class-bag': 'true',\n" + " 'hudson-triggers-TimerTrigger': {'spec': '@daily'}\n" + " }}},\n" + " 'stapler-class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep',\n" + " '$class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep'}"; new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties([pipelineTriggers([cron('@daily')])])", null); new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([pipelineTriggers([cron('@daily')])])"); }
@Issue("JENKINS-34464") @Test public void configRoundTripReverseBuildTrigger() throws Exception { List<JobProperty> properties = Collections.<JobProperty>singletonList(new PipelineTriggersJobProperty(Collections.<Trigger>singletonList(new ReverseBuildTrigger("some-job", Result.UNSTABLE)))); String snippetJson = "{'propertiesMap': {\n" + " 'stapler-class-bag': 'true',\n" + " 'org-jenkinsci-plugins-workflow-job-properties-PipelineTriggersJobProperty': {'triggers': {\n" + " 'stapler-class-bag': 'true',\n" + " 'jenkins-triggers-ReverseBuildTrigger': { 'threshold': 'UNSTABLE', 'upstreamProjects': 'some-job'}\n" + " }}},\n" + " 'stapler-class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep',\n" + " '$class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep'}"; new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties([pipelineTriggers([upstream(threshold: 'UNSTABLE', upstreamProjects: 'some-job')])])", null); new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([pipelineTriggers([upstream(threshold: 'UNSTABLE', upstreamProjects: 'some-job')])])"); }
@Issue("JENKINS-37721") @Test public void configRoundTripSCMTrigger() throws Exception { List<JobProperty> properties = Collections.<JobProperty>singletonList(new PipelineTriggersJobProperty(Collections.<Trigger>singletonList(new SCMTrigger("@daily")))); String snippetJson = "{'propertiesMap': {\n" + " 'stapler-class-bag': 'true',\n" + " 'org-jenkinsci-plugins-workflow-job-properties-PipelineTriggersJobProperty': {'triggers': {\n" + " 'stapler-class-bag': 'true',\n" + " 'hudson-triggers-SCMTrigger': {'scmpoll_spec': '@daily', 'ignorePostCommitHooks': false }\n" + " }}},\n" + " 'stapler-class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep',\n" + " '$class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep'}"; new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties([pipelineTriggers([pollSCM('@daily')])])", null); new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([pipelineTriggers([pollSCM('@daily')])])"); }
@Issue("JENKINS-44621") @Test public void externalTriggersNotRemoved() 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()); List<Trigger> newTriggers = new ArrayList<>(); newTriggers.addAll(triggersJobProperty.getTriggers()); newTriggers.add(new SCMTrigger("1 1 1 * *")); job.removeProperty(triggersJobProperty); job.addProperty(new PipelineTriggersJobProperty(newTriggers)); job.setDefinition(new CpsFlowDefinition(pipelineSourceFromResources("propsTriggersParamsRemoved"), true)); j.buildAndAssertSuccess(job); PipelineTriggersJobProperty newProp = job.getProperty(PipelineTriggersJobProperty.class); assertNotNull(newProp); assertEquals(1, newProp.getTriggers().size()); Trigger t = newProp.getTriggers().get(0); assertNotNull(t); assertTrue(t instanceof SCMTrigger); }