github.com/discordapp/buildkite-agent@v2.6.6+incompatible/clicommand/artifact_upload.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/codegangsta/cli" 8 ) 9 10 var UploadHelpDescription = `Usage: 11 12 buildkite-agent artifact upload <pattern> <destination> [arguments...] 13 14 Description: 15 16 Uploads files to a job as artifacts. 17 18 You need to ensure that the paths are surrounded by quotes otherwise the 19 built-in shell path globbing will provide the files, which is currently not 20 supported. 21 22 Example: 23 24 $ buildkite-agent artifact upload "log/**/*.log" 25 26 You can also upload directly to Amazon S3 if you'd like to host your own artifacts: 27 28 $ export BUILDKITE_S3_ACCESS_KEY_ID=xxx 29 $ export BUILDKITE_S3_SECRET_ACCESS_KEY=yyy 30 $ export BUILDKITE_S3_DEFAULT_REGION=eu-central-1 # default is us-east-1 31 $ export BUILDKITE_S3_ACL=private # default is public-read 32 $ buildkite-agent artifact upload "log/**/*.log" s3://name-of-your-s3-bucket/$BUILDKITE_JOB_ID` 33 34 type ArtifactUploadConfig struct { 35 UploadPaths string `cli:"arg:0" label:"upload paths" validate:"required"` 36 Destination string `cli:"arg:1" label:"destination"` 37 Job string `cli:"job" validate:"required"` 38 AgentAccessToken string `cli:"agent-access-token" validate:"required"` 39 Endpoint string `cli:"endpoint" validate:"required"` 40 NoColor bool `cli:"no-color"` 41 Debug bool `cli:"debug"` 42 DebugHTTP bool `cli:"debug-http"` 43 } 44 45 var ArtifactUploadCommand = cli.Command{ 46 Name: "upload", 47 Usage: "Uploads files to a job as artifacts", 48 Description: UploadHelpDescription, 49 Flags: []cli.Flag{ 50 cli.StringFlag{ 51 Name: "job", 52 Value: "", 53 Usage: "Which job should the artifacts be uploaded to", 54 EnvVar: "BUILDKITE_JOB_ID", 55 }, 56 AgentAccessTokenFlag, 57 EndpointFlag, 58 NoColorFlag, 59 DebugFlag, 60 DebugHTTPFlag, 61 }, 62 Action: func(c *cli.Context) { 63 // The configuration will be loaded into this struct 64 cfg := ArtifactUploadConfig{} 65 66 // Load the configuration 67 if err := cliconfig.Load(c, &cfg); err != nil { 68 logger.Fatal("%s", err) 69 } 70 71 // Setup the any global configuration options 72 HandleGlobalFlags(cfg) 73 74 // Setup the uploader 75 uploader := agent.ArtifactUploader{ 76 APIClient: agent.APIClient{ 77 Endpoint: cfg.Endpoint, 78 Token: cfg.AgentAccessToken, 79 }.Create(), 80 JobID: cfg.Job, 81 Paths: cfg.UploadPaths, 82 Destination: cfg.Destination, 83 } 84 85 // Upload the artifacts 86 if err := uploader.Upload(); err != nil { 87 logger.Fatal("Failed to upload artifacts: %s", err) 88 } 89 }, 90 }