fix: outputs are only set when the job is successful (#1017)
Resolves forgejo/runner#1016 <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1017): <!--number 1017 --><!--line 0 --><!--description Zml4OiBvdXRwdXRzIGFyZSBvbmx5IHNldCB3aGVuIHRoZSBqb2IgaXMgc3VjY2Vzc2Z1bA==-->fix: outputs are only set when the job is successful<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1017 Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
c25bd51857
commit
331979b887
2 changed files with 20 additions and 4 deletions
|
|
@ -130,10 +130,12 @@ func (r *Reporter) Fire(entry *log.Entry) error {
|
|||
}
|
||||
}
|
||||
}
|
||||
if v, ok := entry.Data["jobOutputs"]; ok {
|
||||
_ = r.setOutputs(v.(map[string]string))
|
||||
} else {
|
||||
log.Panicf("received log entry with jobResult, but without jobOutputs -- outputs will be corrupted for this job")
|
||||
if r.state.Result == runnerv1.Result_RESULT_SUCCESS {
|
||||
if v, ok := entry.Data["jobOutputs"]; ok {
|
||||
_ = r.setOutputs(v.(map[string]string))
|
||||
} else {
|
||||
log.Panicf("received log entry with successful jobResult, but without jobOutputs -- outputs will be corrupted for this job")
|
||||
}
|
||||
}
|
||||
}
|
||||
if !r.duringSteps() {
|
||||
|
|
|
|||
|
|
@ -301,6 +301,20 @@ func TestReporter_Fire(t *testing.T) {
|
|||
value, _ := reporter.outputs.Load("key1")
|
||||
assert.EqualValues(t, "value1", value)
|
||||
})
|
||||
|
||||
t.Run("jobResult jobOutputs is absent if not success", func(t *testing.T) {
|
||||
reporter, _, _ := mockReporter(t)
|
||||
|
||||
dataStep0 := map[string]any{
|
||||
"stage": "Post",
|
||||
"stepNumber": 0,
|
||||
"raw_output": true,
|
||||
"jobResult": "skipped",
|
||||
}
|
||||
assert.NoError(t, reporter.Fire(&log.Entry{Message: "skipped!", Data: dataStep0}))
|
||||
|
||||
assert.EqualValues(t, runnerv1.Result_RESULT_SKIPPED, reporter.state.Result)
|
||||
})
|
||||
}
|
||||
|
||||
func TestReporterReportState(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue