github.com/stevenmatthewt/agent@v3.5.4+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/urfave/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 Or upload directly to Google Cloud Storage: 35 36 $ export BUILDKITE_GS_ACL=private 37 $ buildkite-agent artifact upload "log/**/*.log" gs://name-of-your-gs-bucket/$BUILDKITE_JOB_ID` 38 39 type ArtifactUploadConfig struct { 40 UploadPaths string `cli:"arg:0" label:"upload paths" validate:"required"` 41 Destination string `cli:"arg:1" label:"destination" env:"BUILDKITE_ARTIFACT_UPLOAD_DESTINATION"` 42 Job string `cli:"job" validate:"required"` 43 AgentAccessToken string `cli:"agent-access-token" validate:"required"` 44 Endpoint string `cli:"endpoint" validate:"required"` 45 NoColor bool `cli:"no-color"` 46 Debug bool `cli:"debug"` 47 DebugHTTP bool `cli:"debug-http"` 48 } 49 50 var ArtifactUploadCommand = cli.Command{ 51 Name: "upload", 52 Usage: "Uploads files to a job as artifacts", 53 Description: UploadHelpDescription, 54 Flags: []cli.Flag{ 55 cli.StringFlag{ 56 Name: "job", 57 Value: "", 58 Usage: "Which job should the artifacts be uploaded to", 59 EnvVar: "BUILDKITE_JOB_ID", 60 }, 61 AgentAccessTokenFlag, 62 EndpointFlag, 63 NoColorFlag, 64 DebugFlag, 65 DebugHTTPFlag, 66 }, 67 Action: func(c *cli.Context) { 68 // The configuration will be loaded into this struct 69 cfg := ArtifactUploadConfig{} 70 71 // Load the configuration 72 if err := cliconfig.Load(c, &cfg); err != nil { 73 logger.Fatal("%s", err) 74 } 75 76 // Setup the any global configuration options 77 HandleGlobalFlags(cfg) 78 79 // Setup the uploader 80 uploader := agent.ArtifactUploader{ 81 APIClient: agent.APIClient{ 82 Endpoint: cfg.Endpoint, 83 Token: cfg.AgentAccessToken, 84 }.Create(), 85 JobID: cfg.Job, 86 Paths: cfg.UploadPaths, 87 Destination: cfg.Destination, 88 } 89 90 // Upload the artifacts 91 if err := uploader.Upload(); err != nil { 92 logger.Fatal("Failed to upload artifacts: %s", err) 93 } 94 }, 95 }