Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-38454] Make sure we add the triggers before starting.
This was...complex. But it works. We make sure the triggers property has been added before starting, in case the start method for a trigger class expects the trigger to already be present on the job. Existing tests all pass, and the new test failed without the changes to WorkflowJob and PipelineTriggersJobProperty. Phew. Note - I'm working on getting rid of the need for posting hardcoded JSON and just using form manipulation.
- Loading branch information
Showing
5 changed files
with
177 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/test/java/org/jenkinsci/plugins/workflow/job/properties/QueryingMockTrigger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2016, CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
* | ||
*/ | ||
|
||
package org.jenkinsci.plugins.workflow.job.properties; | ||
|
||
import hudson.Extension; | ||
import hudson.model.BuildableItem; | ||
import hudson.model.Item; | ||
import hudson.triggers.Trigger; | ||
import hudson.triggers.TriggerDescriptor; | ||
import jenkins.model.ParameterizedJobMixIn; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class QueryingMockTrigger extends Trigger<BuildableItem> { | ||
|
||
/** elements are true or false for {@code start}, null for {@code stop} */ | ||
public static List<Boolean> startsAndStops = new ArrayList<>(); | ||
|
||
public transient boolean isStarted; | ||
|
||
public transient boolean foundSelf = false; | ||
|
||
@DataBoundConstructor | ||
public QueryingMockTrigger() {} | ||
|
||
@Override public void start(BuildableItem project, boolean newInstance) { | ||
super.start(project, newInstance); | ||
for (Trigger t : ((ParameterizedJobMixIn.ParameterizedJob)project).getTriggers().values()) { | ||
if (t instanceof QueryingMockTrigger) { | ||
foundSelf = true; | ||
} | ||
} | ||
|
||
startsAndStops.add(newInstance); | ||
isStarted = true; | ||
} | ||
|
||
@Override public void stop() { | ||
super.stop(); | ||
startsAndStops.add(null); | ||
isStarted = false; | ||
} | ||
|
||
public Boolean currentStatus() { | ||
if (!startsAndStops.isEmpty()) { | ||
return startsAndStops.get(startsAndStops.size() - 1); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Extension | ||
public static class DescriptorImpl extends TriggerDescriptor { | ||
|
||
@Override public boolean isApplicable(Item item) { | ||
return true; | ||
} | ||
|
||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...ns/workflow/job/properties/PipelineTriggersJobPropertyTest/triggerPresentDuringStart.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "triggerPresent", | ||
"description": "", | ||
"_empty_": [ | ||
"", | ||
"0" | ||
], | ||
"properties": { | ||
"stapler-class-bag": "true", | ||
"jenkins-model-BuildDiscarderProperty": { | ||
"specified": false, | ||
"_empty_": "0", | ||
"strategy": { | ||
"daysToKeepStr": "", | ||
"numToKeepStr": "", | ||
"artifactDaysToKeepStr": "", | ||
"artifactNumToKeepStr": "", | ||
"stapler-class": "hudson.tasks.LogRotator", | ||
"$class": "hudson.tasks.LogRotator" | ||
} | ||
}, | ||
"hudson-model-ParametersDefinitionProperty": { | ||
"specified": false | ||
}, | ||
"org-jenkinsci-plugins-workflow-job-properties-PipelineTriggersJobProperty": { | ||
"triggers": { | ||
"stapler-class-bag": "true", | ||
"org-jenkinsci-plugins-workflow-job-properties-QueryingMockTrigger": { | ||
|
||
} | ||
} | ||
} | ||
}, | ||
"hasCustomQuietPeriod": false, | ||
"quiet_period": "0", | ||
"displayNameOrNull": "", | ||
"definition": { | ||
"script": "", | ||
"_empty_": [ | ||
"try sample Pipeline...", | ||
"\u0001\u0001" | ||
], | ||
"sandbox": true, | ||
"stapler-class": "org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition", | ||
"$class": "org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" | ||
}, | ||
"core:apply": "" | ||
} |