diff --git a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java index 4002dba5..dcce8d4c 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java @@ -553,6 +553,14 @@ private String key() { // super.reload() forces result to be FAILURE, so working around that new XmlFile(XSTREAM,new File(getRootDir(),"build.xml")).unmarshal(this); + synchronized (getMetadataGuard()) { + if (Boolean.TRUE.equals(completed) && executionLoaded) { + var _execution = execution; + if (_execution != null) { + _execution.onLoad(new Owner(this)); + } + } + } } @Override protected void onLoad() { diff --git a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java index aa3094e9..ed84651e 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java @@ -30,6 +30,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.emptyArray; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertEquals; @@ -618,6 +619,15 @@ private static String checkoutString(GitSampleRepoRule repo, boolean changelog, ", userRemoteConfigs: [[url: $/" + repo.fileUrl() + "/$]]])\n"; } + @Test public void reloadOwner() throws Exception { + WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "reloadOwner"); + p.setDefinition(new CpsFlowDefinition("", true)); + WorkflowRun b = r.buildAndAssertSuccess(p); + assertThat("right owner before reload", b.getExecution().getOwner(), is(b.asFlowExecutionOwner())); + b.reload(); + assertThat("right owner after reload", b.getExecution().getOwner(), is(b.asFlowExecutionOwner())); + } + // This test is to ensure that the shortDescription on the CancelCause is escaped properly on summary.jelly @Issue("SECURITY-3042") @Test public void escapedDisplayNameAfterAbort() throws Exception {