diff --git a/pipeline/runtime/common.go b/pipeline/runtime/common.go index 9beea67..65eb594 100644 --- a/pipeline/runtime/common.go +++ b/pipeline/runtime/common.go @@ -88,6 +88,12 @@ func fetchOutputVariables(outputFile string, out io.Writer) (map[string]string, log.Out = out outputs := make(map[string]string) + + // The output file maybe not exist - we don't consider that an error + if _, err := os.Stat(outputFile); os.IsNotExist(err) { + return outputs, nil + } + f, err := os.Open(outputFile) if err != nil { log.WithError(err).WithField("outputFile", outputFile).Errorln("failed to open output file") diff --git a/pipeline/runtime/run.go b/pipeline/runtime/run.go index 3c3b8ef..a7b0d3e 100644 --- a/pipeline/runtime/run.go +++ b/pipeline/runtime/run.go @@ -32,6 +32,7 @@ func executeRunStep(ctx context.Context, engine *engine.Engine, r *api.StartStep } outputFile := fmt.Sprintf("%s/%s.out", pipeline.SharedVolPath, step.ID) + step.Envs["DRONE_OUTPUT"] = outputFile if len(r.OutputVars) > 0 { step.Command[0] += getOutputVarCmd(step.Entrypoint, r.OutputVars, outputFile) @@ -52,18 +53,16 @@ func executeRunStep(ctx context.Context, engine *engine.Engine, r *api.StartStep } artifact, _ := fetchArtifactDataFromArtifactFile(artifactFile, out) - if len(r.OutputVars) > 0 { - if exited != nil && exited.Exited && exited.ExitCode == 0 { - outputs, err := fetchOutputVariables(outputFile, out) // nolint:govet - if err != nil { - return exited, nil, nil, err - } - // Delete output variable file - if ferr := os.Remove(outputFile); ferr != nil { - logrus.WithError(ferr).WithField("file", outputFile).Warnln("could not remove output file") - } - return exited, outputs, artifact, err + if exited != nil && exited.Exited && exited.ExitCode == 0 { + outputs, err := fetchOutputVariables(outputFile, out) // nolint:govet + if err != nil { + return exited, nil, nil, err + } + // Delete output variable file + if ferr := os.Remove(outputFile); ferr != nil { + logrus.WithError(ferr).WithField("file", outputFile).Warnln("could not remove output file") } + return exited, outputs, artifact, err } return exited, nil, artifact, err