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

[JENKINS-64553] fix ItemListener not called after updating job via REST API or CLI #9304

Merged
merged 1 commit into from
May 27, 2024
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
1 change: 1 addition & 0 deletions core/src/main/java/hudson/model/AbstractItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ public void updateByXml(Source source) throws IOException {
// if everything went well, commit this new version
out.commit();
SaveableListener.fireOnChange(this, getConfigFile());
ItemListener.fireOnUpdated(this);

} finally {
out.abort(); // don't leave anything behind
Expand Down
21 changes: 21 additions & 0 deletions test/src/test/java/hudson/model/listeners/ItemListenerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

/**
Expand All @@ -58,6 +59,12 @@ public void setUp() {
@Override public void onCopied(Item src, Item item) {
events.append('Y');
}

@Override
public void onUpdated(Item item) {
events.append('U');
}

};
ItemListener.all().add(0, listener);
}
Expand All @@ -71,4 +78,18 @@ public void onCreatedViaCLI() {
assertNotNull("job should be created: " + result, j.jenkins.getItem("testJob"));
assertEquals("onCreated event should be triggered: " + result, "C", events.toString());
}

@Issue("JENKINS-64553")
@Test
public void onUpdatedViaCLI() {
CLICommandInvoker.Result result = new CLICommandInvoker(j, "create-job").
withStdin(new ByteArrayInputStream("<project/>".getBytes(Charset.defaultCharset()))).
invokeWithArgs("testJob");
assertThat(result, CLICommandInvoker.Matcher.succeeded());
result = new CLICommandInvoker(j, "update-job").
withStdin(new ByteArrayInputStream("<project><actions/><builders/><publishers/><buildWrappers/></project>".getBytes(Charset.defaultCharset()))).
invokeWithArgs("testJob");
assertThat(result, CLICommandInvoker.Matcher.succeeded());
assertEquals("onUpdated event should be triggered: " + result, "CU", events.toString());
}
}
Loading