forked from buildkite/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artifact_upload.go
95 lines (77 loc) · 2.76 KB
/
artifact_upload.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
package clicommand
import (
"github.com/buildkite/agent/agent"
"github.com/buildkite/agent/cliconfig"
"github.com/buildkite/agent/logger"
"github.com/urfave/cli"
)
var UploadHelpDescription = `Usage:
buildkite-agent artifact upload <pattern> <destination> [arguments...]
Description:
Uploads files to a job as artifacts.
You need to ensure that the paths are surrounded by quotes otherwise the
built-in shell path globbing will provide the files, which is currently not
supported.
Example:
$ buildkite-agent artifact upload "log/**/*.log"
You can also upload directly to Amazon S3 if you'd like to host your own artifacts:
$ export BUILDKITE_S3_ACCESS_KEY_ID=xxx
$ export BUILDKITE_S3_SECRET_ACCESS_KEY=yyy
$ export BUILDKITE_S3_DEFAULT_REGION=eu-central-1 # default is us-east-1
$ export BUILDKITE_S3_ACL=private # default is public-read
$ buildkite-agent artifact upload "log/**/*.log" s3://name-of-your-s3-bucket/$BUILDKITE_JOB_ID
Or upload directly to Google Cloud Storage:
$ export BUILDKITE_GS_ACL=private
$ buildkite-agent artifact upload "log/**/*.log" gs://name-of-your-gs-bucket/$BUILDKITE_JOB_ID`
type ArtifactUploadConfig struct {
UploadPaths string `cli:"arg:0" label:"upload paths" validate:"required"`
Destination string `cli:"arg:1" label:"destination" env:"BUILDKITE_ARTIFACT_UPLOAD_DESTINATION"`
Job string `cli:"job" 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 ArtifactUploadCommand = cli.Command{
Name: "upload",
Usage: "Uploads files to a job as artifacts",
Description: UploadHelpDescription,
Flags: []cli.Flag{
cli.StringFlag{
Name: "job",
Value: "",
Usage: "Which job should the artifacts be uploaded to",
EnvVar: "BUILDKITE_JOB_ID",
},
AgentAccessTokenFlag,
EndpointFlag,
NoColorFlag,
DebugFlag,
DebugHTTPFlag,
},
Action: func(c *cli.Context) {
// The configuration will be loaded into this struct
cfg := ArtifactUploadConfig{}
// 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 uploader
uploader := agent.ArtifactUploader{
APIClient: agent.APIClient{
Endpoint: cfg.Endpoint,
Token: cfg.AgentAccessToken,
}.Create(),
JobID: cfg.Job,
Paths: cfg.UploadPaths,
Destination: cfg.Destination,
}
// Upload the artifacts
if err := uploader.Upload(); err != nil {
logger.Fatal("Failed to upload artifacts: %s", err)
}
},
}