forked from buildkite/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artifact_download.go
99 lines (81 loc) · 2.99 KB
/
artifact_download.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package clicommand
import (
"github.com/buildkite/agent/agent"
"github.com/buildkite/agent/cliconfig"
"github.com/buildkite/agent/logger"
"github.com/codegangsta/cli"
)
var DownloadHelpDescription = `Usage:
buildkite-agent artifact download [arguments...]
Description:
Downloads artifacts from Buildkite to the local machine.
Note: You need to ensure that your search query is surrounded by quotes if
using a wild card as the built-in shell path globbing will provide files,
which will break the download.
Example:
$ buildkite-agent artifact download "pkg/*.tar.gz" . --build xxx
This will search across all the artifacts for the build with files that match that part.
The first argument is the search query, and the second argument is the download destination.
If you're trying to download a specific file, and there are multiple artifacts from different
jobs, you can target the particular job you want to download the artifact from:
$ buildkite-agent artifact download "pkg/*.tar.gz" . --step "tests" --build xxx
You can also use the step's jobs id (provided by the environment variable $BUILDKITE_JOB_ID)`
type ArtifactDownloadConfig struct {
Query string `cli:"arg:0" label:"artifact search query" validate:"required"`
Destination string `cli:"arg:1" label:"artifact download path" validate:"required"`
Step string `cli:"step"`
Build string `cli:"build" validate:"required"`
AgentAccessToken string `cli:"agent-access-token" validate:"required"`
Endpoint string `cli:"endpoint" validate:"required"`
NoColor bool `cli:"no-color"`
Debug bool `cli:"debug"`
DebugHTTP bool `cli:"debug-http"`
}
var ArtifactDownloadCommand = cli.Command{
Name: "download",
Usage: "Downloads artifacts from Buildkite to the local machine",
Description: DownloadHelpDescription,
Flags: []cli.Flag{
cli.StringFlag{
Name: "step",
Value: "",
Usage: "Scope the search to a paticular step by using either it's name of job ID",
},
cli.StringFlag{
Name: "build",
Value: "",
EnvVar: "BUILDKITE_BUILD_ID",
Usage: "The build that the artifacts were uploaded to",
},
AgentAccessTokenFlag,
EndpointFlag,
NoColorFlag,
DebugFlag,
DebugHTTPFlag,
},
Action: func(c *cli.Context) {
// The configuration will be loaded into this struct
cfg := ArtifactDownloadConfig{}
// Load the configuration
if err := cliconfig.Load(c, &cfg); err != nil {
logger.Fatal("%s", err)
}
// Setup the any global configuration options
HandleGlobalFlags(cfg)
// Setup the downloader
downloader := agent.ArtifactDownloader{
APIClient: agent.APIClient{
Endpoint: cfg.Endpoint,
Token: cfg.AgentAccessToken,
}.Create(),
Query: cfg.Query,
Destination: cfg.Destination,
BuildID: cfg.Build,
Step: cfg.Step,
}
// Download the artifacts
if err := downloader.Download(); err != nil {
logger.Fatal("Failed to download artifacts: %s", err)
}
},
}