Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to remove trigger #126

Merged
merged 5 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -500,14 +500,26 @@ public List<TriggerDescriptor> getTriggerDescriptors() {
return result;
}

/**
* Update an existing trigger or add a new one.
* @param trigger Target trigger instance.
*/
public void addTrigger(Trigger trigger) {
removeTrigger(trigger);
triggers.add(trigger);
trigger.start(this, true);
}

/**
* Remove an existing trigger.
* @param trigger Target trigger instance.
*/
public void removeTrigger(Trigger trigger) {
LinuxSuRen marked this conversation as resolved.
Show resolved Hide resolved
Trigger old = triggers.get(trigger.getDescriptor());
if (old != null) {
old.stop();
triggers.remove(old);
}
triggers.add(trigger);
trigger.start(this, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,18 @@ public void triggersRoundtrip() throws Exception {

}

@Test
public void cleanTriggers() throws Exception {
SampleComputedFolder s = r.jenkins.createProject(SampleComputedFolder.class, "s");
s.addTrigger(new PeriodicFolderTrigger("30m"));
LinuxSuRen marked this conversation as resolved.
Show resolved Hide resolved

assertEquals(1, s.getTriggers().size());

s.removeTrigger(new PeriodicFolderTrigger("30m"));

assertEquals(0, s.getTriggers().size());
}

@Test
@Issue("JENKINS-42511")
public void concurrentEvents() throws Exception {
Expand Down