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