Skip to content

Commit

Permalink
fix (worker): (workflow) download dest of artifact
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored and fsamin committed Sep 24, 2017
1 parent 80d6baf commit 6708694
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions engine/worker/builtin_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/url"
"os"
"path"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -183,7 +184,7 @@ func runArtifactDownload(w *currentWorker) BuiltInAction {
number := sdk.ParameterValue(*params, "cds.run.number")
enabled := sdk.ParameterValue(*params, "enabled") != "false"

path := sdk.ParameterValue(a.Parameters, "path")
destPath := sdk.ParameterValue(a.Parameters, "path")
tag := sdk.ParameterValue(a.Parameters, "tag")

if !enabled {
Expand All @@ -195,7 +196,7 @@ func runArtifactDownload(w *currentWorker) BuiltInAction {
sendLog("tag variable can not be used with CDS Workflow - ignored.")
}

sendLog(fmt.Sprintf("Downloading artifacts from workflow into '%s'...", path))
sendLog(fmt.Sprintf("Downloading artifacts from workflow into '%s'...", destPath))

n, err := strconv.ParseInt(number, 10, 64)
if err != nil {
Expand All @@ -214,26 +215,27 @@ func runArtifactDownload(w *currentWorker) BuiltInAction {
}

for _, a := range artifacts {
f, err := os.OpenFile(a.Name, os.O_RDWR|os.O_CREATE, os.FileMode(a.Perm))
destFile := path.Join(destPath, a.Name)
f, err := os.OpenFile(destFile, os.O_RDWR|os.O_CREATE, os.FileMode(a.Perm))
if err != nil {
res.Status = sdk.StatusFail.String()
res.Reason = err.Error()
log.Warning("Cannot download artifact (OpenFile) %s: %s", a.Name, err)
log.Warning("Cannot download artifact (OpenFile) %s: %s", destFile, err)
sendLog(res.Reason)
return res
}
sendLog(fmt.Sprintf("downloading artifact %s from workflow %s/%s on run %d...", a.Name, project, workflow, n))
sendLog(fmt.Sprintf("downloading artifact %s from workflow %s/%s on run %d...", destFile, project, workflow, n))
if err := w.client.WorkflowNodeRunArtifactDownload(project, workflow, a.ID, f); err != nil {
res.Status = sdk.StatusFail.String()
res.Reason = err.Error()
log.Warning("Cannot download artifact %s: %s", a.Name, err)
log.Warning("Cannot download artifact %s: %s", destFile, err)
sendLog(res.Reason)
return res
}
if err := f.Close(); err != nil {
res.Status = sdk.StatusFail.String()
res.Reason = err.Error()
log.Warning("Cannot download artifact %s: %s", a.Name, err)
log.Warning("Cannot download artifact %s: %s", destFile, err)
sendLog(res.Reason)
return res
}
Expand Down

0 comments on commit 6708694

Please sign in to comment.