Skip to content

Commit

Permalink
[JENKINS-64553] fix ItemListener not called after updating job via RE…
Browse files Browse the repository at this point in the history
…ST API or CLI (#9304)

[JENKINS-64553] call ItemListener after updating job via cli

when a job is updated via REST API or CLI, the
ItemListener.fireOnUpdated is now called to inform about the change.
  • Loading branch information
mawinter69 committed May 27, 2024
1 parent c46dc4b commit dae1737
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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());
}
}

0 comments on commit dae1737

Please sign in to comment.