Skip to content

Commit

Permalink
Merge pull request #21 from harness/iac-1303-docker-output-support
Browse files Browse the repository at this point in the history
feat: [IAC-1301]: Support for dynamic output vars via DRONE_OUTPUT
  • Loading branch information
vistaarjuneja authored Dec 12, 2023
2 parents 19877b0 + 748cf79 commit 3e7f6c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
6 changes: 6 additions & 0 deletions pipeline/runtime/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
21 changes: 10 additions & 11 deletions pipeline/runtime/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 3e7f6c9

Please sign in to comment.