Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultConfigFilePaths() (paths []string)
- func DefaultShell() string
- func HandleGlobalFlags(cfg interface{})
- type AgentStartConfig
- type AnnotateConfig
- type ArtifactDownloadConfig
- type ArtifactShasumConfig
- type ArtifactUploadConfig
- type BootstrapConfig
- type MetaDataExistsConfig
- type MetaDataGetConfig
- type MetaDataSetConfig
- type PipelineUploadConfig
Constants ¶
View Source
const (
DefaultEndpoint = "https://agent.buildkite.com/v3"
)
Variables ¶
View Source
var AgentAccessTokenFlag = cli.StringFlag{
Name: "agent-access-token",
Value: "",
Usage: "The access token used to identify the agent",
EnvVar: "BUILDKITE_AGENT_ACCESS_TOKEN",
}
View Source
var AgentStartCommand = cli.Command{ Name: "start", Usage: "Starts a Buildkite agent", Description: StartDescription, Flags: []cli.Flag{ cli.StringFlag{ Name: "config", Value: "", Usage: "Path to a configuration file", EnvVar: "BUILDKITE_AGENT_CONFIG", }, cli.StringFlag{ Name: "token", Value: "", Usage: "Your account agent token", EnvVar: "BUILDKITE_AGENT_TOKEN", }, cli.StringFlag{ Name: "name", Value: "", Usage: "The name of the agent", EnvVar: "BUILDKITE_AGENT_NAME", }, cli.StringFlag{ Name: "priority", Value: "", Usage: "The priority of the agent (higher priorities are assigned work first)", EnvVar: "BUILDKITE_AGENT_PRIORITY", }, cli.BoolFlag{ Name: "disconnect-after-job", Usage: "Disconnect the agent after running a job", EnvVar: "BUILDKITE_AGENT_DISCONNECT_AFTER_JOB", }, cli.IntFlag{ Name: "disconnect-after-job-timeout", Value: 120, Usage: "When --disconnect-after-job is specified, the number of seconds to wait for a job before shutting down", EnvVar: "BUILDKITE_AGENT_DISCONNECT_AFTER_JOB_TIMEOUT", }, cli.StringFlag{ Name: "shell", Value: DefaultShell(), Usage: "The shell commamnd used to interpret build commands, e.g /bin/bash -e -c", EnvVar: "BUILDKITE_SHELL", }, cli.StringSliceFlag{ Name: "tags", Value: &cli.StringSlice{}, Usage: "A comma-separated list of tags for the agent (e.g. \"linux\" or \"mac,xcode=8\")", EnvVar: "BUILDKITE_AGENT_TAGS", }, cli.BoolFlag{ Name: "tags-from-host", Usage: "Include tags from the host (hostname, machine-id, os)", EnvVar: "BUILDKITE_AGENT_TAGS_FROM_HOST", }, cli.BoolFlag{ Name: "tags-from-ec2", Usage: "Include the host's EC2 meta-data as tags (instance-id, instance-type, and ami-id)", EnvVar: "BUILDKITE_AGENT_TAGS_FROM_EC2", }, cli.BoolFlag{ Name: "tags-from-ec2-tags", Usage: "Include the host's EC2 tags as tags", EnvVar: "BUILDKITE_AGENT_TAGS_FROM_EC2_TAGS", }, cli.BoolFlag{ Name: "tags-from-gcp", Usage: "Include the host's Google Cloud meta-data as tags (instance-id, machine-type, preemptible, project-id, region, and zone)", EnvVar: "BUILDKITE_AGENT_TAGS_FROM_GCP", }, cli.DurationFlag{ Name: "wait-for-ec2-tags-timeout", Usage: "The amount of time to wait for tags from EC2 before proceeding", EnvVar: "BUILDKITE_AGENT_WAIT_FOR_EC2_TAGS_TIMEOUT", Value: time.Second * 10, }, cli.StringFlag{ Name: "git-clone-flags", Value: "-v", Usage: "Flags to pass to the \"git clone\" command", EnvVar: "BUILDKITE_GIT_CLONE_FLAGS", }, cli.StringFlag{ Name: "git-clean-flags", Value: "-fxdq", Usage: "Flags to pass to \"git clean\" command", EnvVar: "BUILDKITE_GIT_CLEAN_FLAGS", }, cli.StringFlag{ Name: "bootstrap-script", Value: "", Usage: "The command that is executed for bootstrapping a job, defaults to the bootstrap sub-command of this binary", EnvVar: "BUILDKITE_BOOTSTRAP_SCRIPT_PATH", }, cli.StringFlag{ Name: "build-path", Value: "", Usage: "Path to where the builds will run from", EnvVar: "BUILDKITE_BUILD_PATH", }, cli.StringFlag{ Name: "hooks-path", Value: "", Usage: "Directory where the hook scripts are found", EnvVar: "BUILDKITE_HOOKS_PATH", }, cli.StringFlag{ Name: "plugins-path", Value: "", Usage: "Directory where the plugins are saved to", EnvVar: "BUILDKITE_PLUGINS_PATH", }, cli.BoolFlag{ Name: "timestamp-lines", Usage: "Prepend timestamps on each line of output.", EnvVar: "BUILDKITE_TIMESTAMP_LINES", }, cli.BoolFlag{ Name: "no-pty", Usage: "Do not run jobs within a pseudo terminal", EnvVar: "BUILDKITE_NO_PTY", }, cli.BoolFlag{ Name: "no-ssh-keyscan", Usage: "Don't automatically run ssh-keyscan before checkout", EnvVar: "BUILDKITE_NO_SSH_KEYSCAN", }, cli.BoolFlag{ Name: "no-command-eval", Usage: "Don't allow this agent to run arbitrary console commands, including plugins", EnvVar: "BUILDKITE_NO_COMMAND_EVAL", }, cli.BoolFlag{ Name: "no-plugins", Usage: "Don't allow this agent to load plugins", EnvVar: "BUILDKITE_NO_PLUGINS", }, cli.BoolFlag{ Name: "no-local-hooks", Usage: "Don't allow local hooks to be run from checked out repositories", EnvVar: "BUILDKITE_NO_LOCAL_HOOKS", }, cli.BoolFlag{ Name: "no-git-submodules", Usage: "Don't automatically checkout git submodules", EnvVar: "BUILDKITE_NO_GIT_SUBMODULES,BUILDKITE_DISABLE_GIT_SUBMODULES", }, ExperimentsFlag, EndpointFlag, NoColorFlag, DebugFlag, DebugHTTPFlag, cli.StringSliceFlag{ Name: "meta-data", Value: &cli.StringSlice{}, Hidden: true, EnvVar: "BUILDKITE_AGENT_META_DATA", }, cli.BoolFlag{ Name: "meta-data-ec2", Hidden: true, EnvVar: "BUILDKITE_AGENT_META_DATA_EC2", }, cli.BoolFlag{ Name: "meta-data-ec2-tags", Hidden: true, EnvVar: "BUILDKITE_AGENT_TAGS_FROM_EC2_TAGS", }, cli.BoolFlag{ Name: "meta-data-gcp", Hidden: true, EnvVar: "BUILDKITE_AGENT_META_DATA_GCP", }, cli.BoolFlag{ Name: "no-automatic-ssh-fingerprint-verification", Hidden: true, EnvVar: "BUILDKITE_NO_AUTOMATIC_SSH_FINGERPRINT_VERIFICATION", }, }, Action: func(c *cli.Context) { cfg := AgentStartConfig{} loader := cliconfig.Loader{ CLI: c, Config: &cfg, DefaultConfigFilePaths: DefaultConfigFilePaths(), } if err := loader.Load(); err != nil { logger.Fatal("%s", err) } HandleGlobalFlags(cfg) if runtime.GOOS == "windows" { cfg.NoPTY = true } if cfg.BootstrapScript == "" { cfg.BootstrapScript = fmt.Sprintf("%s bootstrap", shellwords.Quote(os.Args[0])) } if c.IsSet("no-plugins") && cfg.NoPlugins == false { msg := `Plugins have been specifically enabled, despite %s being enabled. ` + `Plugins can execute arbitrary hooks and commands, make sure you are ` + `whitelisting your plugins in ` + `your environment hook.` switch { case cfg.NoCommandEval: logger.Warn(msg, `no-command-eval`) case cfg.NoLocalHooks: logger.Warn(msg, `no-local-hooks`) } } if (cfg.NoCommandEval || cfg.NoLocalHooks) && !c.IsSet("no-plugins") { cfg.NoPlugins = true } if cfg.Shell == "" { cfg.Shell = DefaultShell() } if cfg.DisconnectAfterJob && cfg.DisconnectAfterJobTimeout < 120 { logger.Fatal("The timeout for `disconnect-after-job` must be at least 120 seconds") } var ec2TagTimeout time.Duration if t := cfg.WaitForEC2TagsTimeout; t != "" { var err error ec2TagTimeout, err = time.ParseDuration(t) if err != nil { logger.Fatal("Failed to parse ec2 tag timeout: %v", err) } } pool := agent.AgentPool{ Token: cfg.Token, Name: cfg.Name, Priority: cfg.Priority, Tags: cfg.Tags, TagsFromEC2: cfg.TagsFromEC2, TagsFromEC2Tags: cfg.TagsFromEC2Tags, TagsFromGCP: cfg.TagsFromGCP, TagsFromHost: cfg.TagsFromHost, WaitForEC2TagsTimeout: ec2TagTimeout, Endpoint: cfg.Endpoint, AgentConfiguration: &agent.AgentConfiguration{ BootstrapScript: cfg.BootstrapScript, BuildPath: cfg.BuildPath, HooksPath: cfg.HooksPath, PluginsPath: cfg.PluginsPath, GitCloneFlags: cfg.GitCloneFlags, GitCleanFlags: cfg.GitCleanFlags, GitSubmodules: !cfg.NoGitSubmodules, SSHKeyscan: !cfg.NoSSHKeyscan, CommandEval: !cfg.NoCommandEval, PluginsEnabled: !cfg.NoPlugins, LocalHooksEnabled: !cfg.NoLocalHooks, RunInPty: !cfg.NoPTY, TimestampLines: cfg.TimestampLines, DisconnectAfterJob: cfg.DisconnectAfterJob, DisconnectAfterJobTimeout: cfg.DisconnectAfterJobTimeout, Shell: cfg.Shell, }, } if loader.File != nil { pool.ConfigFilePath = loader.File.Path pool.AgentConfiguration.ConfigPath = loader.File.Path } if err := pool.Start(); err != nil { logger.Fatal("%s", err) } }, }
View Source
var AnnotateCommand = cli.Command{ Name: "annotate", Usage: "Annotate the build page within the Buildkite UI with text from within a Buildkite job", Description: AnnotateHelpDescription, Flags: []cli.Flag{ cli.StringFlag{ Name: "context", Usage: "The context of the annotation used to differentiate this annotation from others", EnvVar: "BUILDKITE_ANNOTATION_CONTEXT", }, cli.StringFlag{ Name: "style", Usage: "The style of the annotation (`success`, `info`, `warning` or `error`)", EnvVar: "BUILDKITE_ANNOTATION_STYLE", }, cli.BoolFlag{ Name: "append", Usage: "Append to the body of an existing annotation", EnvVar: "BUILDKITE_ANNOTATION_APPEND", }, cli.StringFlag{ Name: "job", Value: "", Usage: "Which job should the annotation come from", EnvVar: "BUILDKITE_JOB_ID", }, AgentAccessTokenFlag, EndpointFlag, NoColorFlag, DebugFlag, DebugHTTPFlag, }, Action: func(c *cli.Context) { cfg := AnnotateConfig{} loader := cliconfig.Loader{CLI: c, Config: &cfg} if err := loader.Load(); err != nil { logger.Fatal("%s", err) } HandleGlobalFlags(cfg) var body string var err error if cfg.Body != "" { body = cfg.Body } else if stdin.IsReadable() { logger.Info("Reading annotation body from STDIN") stdin, err := ioutil.ReadAll(os.Stdin) if err != nil { logger.Fatal("Failed to read from STDIN: %s", err) } body = string(stdin[:]) } client := agent.APIClient{ Endpoint: cfg.Endpoint, Token: cfg.AgentAccessToken, }.Create() annotation := &api.Annotation{ Body: body, Style: cfg.Style, Context: cfg.Context, Append: cfg.Append, } err = retry.Do(func(s *retry.Stats) error { resp, err := client.Annotations.Create(cfg.Job, annotation) if resp != nil && (resp.StatusCode == 401 || resp.StatusCode == 404 || resp.StatusCode == 400) { s.Break() return err } if err != nil { logger.Warn("%s (%s)", err, s) } return err }, &retry.Config{Maximum: 5, Interval: 1 * time.Second, Jitter: true}) if err != nil { logger.Fatal("Failed to annotate build: %s", err) } logger.Info("Successfully annotated build") }, }
View Source
var AnnotateHelpDescription = `` /* 1178-byte string literal not displayed */
View Source
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 or 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) { cfg := ArtifactDownloadConfig{} if err := cliconfig.Load(c, &cfg); err != nil { logger.Fatal("%s", err) } HandleGlobalFlags(cfg) 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, } if err := downloader.Download(); err != nil { logger.Fatal("Failed to download artifacts: %s", err) } }, }
View Source
var ArtifactShasumCommand = cli.Command{ Name: "shasum", Usage: "Prints the SHA-1 checksum for the artifact provided to STDOUT", Description: ShasumHelpDescription, 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) { cfg := ArtifactShasumConfig{} if err := cliconfig.Load(c, &cfg); err != nil { logger.Fatal("%s", err) } HandleGlobalFlags(cfg) searcher := agent.ArtifactSearcher{ APIClient: agent.APIClient{ Endpoint: cfg.Endpoint, Token: cfg.AgentAccessToken, }.Create(), BuildID: cfg.Build, } artifacts, err := searcher.Search(cfg.Query, cfg.Step) if err != nil { logger.Fatal("Failed to find artifacts: %s", err) } artifactsFoundLength := len(artifacts) if artifactsFoundLength == 0 { logger.Fatal("No artifacts found for downloading") } else if artifactsFoundLength > 1 { logger.Fatal("Multiple artifacts were found. Try being more specific with the search or scope by step") } else { logger.Debug("Artifact \"%s\" found", artifacts[0].Path) fmt.Printf("%s\n", artifacts[0].Sha1Sum) } }, }
View Source
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) { cfg := ArtifactUploadConfig{} if err := cliconfig.Load(c, &cfg); err != nil { logger.Fatal("%s", err) } HandleGlobalFlags(cfg) uploader := agent.ArtifactUploader{ APIClient: agent.APIClient{ Endpoint: cfg.Endpoint, Token: cfg.AgentAccessToken, }.Create(), JobID: cfg.Job, Paths: cfg.UploadPaths, Destination: cfg.Destination, } if err := uploader.Upload(); err != nil { logger.Fatal("Failed to upload artifacts: %s", err) } }, }
View Source
var BootstrapCommand = cli.Command{ Name: "bootstrap", Usage: "Run a Buildkite job locally", Description: BootstrapHelpDescription, Flags: []cli.Flag{ cli.StringFlag{ Name: "command", Value: "", Usage: "The command to run", EnvVar: "BUILDKITE_COMMAND", }, cli.StringFlag{ Name: "job", Value: "", Usage: "The ID of the job being run", EnvVar: "BUILDKITE_JOB_ID", }, cli.StringFlag{ Name: "repository", Value: "", Usage: "The repository to clone and run the job from", EnvVar: "BUILDKITE_REPO", }, cli.StringFlag{ Name: "commit", Value: "", Usage: "The commit to checkout in the repository", EnvVar: "BUILDKITE_COMMIT", }, cli.StringFlag{ Name: "branch", Value: "", Usage: "The branch the commit is in", EnvVar: "BUILDKITE_BRANCH", }, cli.StringFlag{ Name: "tag", Value: "", Usage: "The tag the commit", EnvVar: "BUILDKITE_TAG", }, cli.StringFlag{ Name: "refspec", Value: "", Usage: "Optional refspec to override git fetch", EnvVar: "BUILDKITE_REFSPEC", }, cli.StringFlag{ Name: "plugins", Value: "", Usage: "The plugins for the job", EnvVar: "BUILDKITE_PLUGINS", }, cli.StringFlag{ Name: "pullrequest", Value: "", Usage: "The number/id of the pull request this commit belonged to", EnvVar: "BUILDKITE_PULL_REQUEST", }, cli.StringFlag{ Name: "agent", Value: "", Usage: "The name of the agent running the job", EnvVar: "BUILDKITE_AGENT_NAME", }, cli.StringFlag{ Name: "organization", Value: "", Usage: "The slug of the organization that the job is a part of", EnvVar: "BUILDKITE_ORGANIZATION_SLUG", }, cli.StringFlag{ Name: "pipeline", Value: "", Usage: "The slug of the pipeline that the job is a part of", EnvVar: "BUILDKITE_PIPELINE_SLUG", }, cli.StringFlag{ Name: "pipeline-provider", Value: "", Usage: "The id of the SCM provider that the repository is hosted on", EnvVar: "BUILDKITE_PIPELINE_PROVIDER", }, cli.StringFlag{ Name: "artifact-upload-paths", Value: "", Usage: "Paths to files to automatically upload at the end of a job", EnvVar: "BUILDKITE_ARTIFACT_PATHS", }, cli.StringFlag{ Name: "artifact-upload-destination", Value: "", Usage: "A custom location to upload artifact paths to (i.e. s3://my-custom-bucket)", EnvVar: "BUILDKITE_ARTIFACT_UPLOAD_DESTINATION", }, cli.BoolFlag{ Name: "clean-checkout", Usage: "Whether or not the bootstrap should remove the existing repository before running the command", EnvVar: "BUILDKITE_CLEAN_CHECKOUT", }, cli.StringFlag{ Name: "git-clone-flags", Value: "-v", Usage: "Flags to pass to \"git clone\" command", EnvVar: "BUILDKITE_GIT_CLONE_FLAGS", }, cli.StringFlag{ Name: "git-clean-flags", Value: "-fxdq", Usage: "Flags to pass to \"git clean\" command", EnvVar: "BUILDKITE_GIT_CLEAN_FLAGS", }, cli.StringFlag{ Name: "bin-path", Value: "", Usage: "Directory where the buildkite-agent binary lives", EnvVar: "BUILDKITE_BIN_PATH", }, cli.StringFlag{ Name: "build-path", Value: "", Usage: "Directory where builds will be created", EnvVar: "BUILDKITE_BUILD_PATH", }, cli.StringFlag{ Name: "hooks-path", Value: "", Usage: "Directory where the hook scripts are found", EnvVar: "BUILDKITE_HOOKS_PATH", }, cli.StringFlag{ Name: "plugins-path", Value: "", Usage: "Directory where the plugins are saved to", EnvVar: "BUILDKITE_PLUGINS_PATH", }, cli.BoolTFlag{ Name: "command-eval", Usage: "Allow running of arbitary commands", EnvVar: "BUILDKITE_COMMAND_EVAL", }, cli.BoolTFlag{ Name: "plugins-enabled", Usage: "Allow plugins to be run", EnvVar: "BUILDKITE_PLUGINS_ENABLED", }, cli.BoolTFlag{ Name: "local-hooks-enabled", Usage: "Allow local hooks to be run", EnvVar: "BUILDKITE_LOCAL_HOOKS_ENABLED", }, cli.BoolTFlag{ Name: "ssh-keyscan", Usage: "Automatically run ssh-keyscan before checkout", EnvVar: "BUILDKITE_SSH_KEYSCAN", }, cli.BoolTFlag{ Name: "git-submodules", Usage: "Enable git submodules", EnvVar: "BUILDKITE_GIT_SUBMODULES", }, cli.BoolTFlag{ Name: "pty", Usage: "Run jobs within a pseudo terminal", EnvVar: "BUILDKITE_PTY", }, cli.StringFlag{ Name: "shell", Usage: "The shell to use to interpret build commands", EnvVar: "BUILDKITE_SHELL", Value: DefaultShell(), }, DebugFlag, }, Action: func(c *cli.Context) { cfg := BootstrapConfig{} if err := cliconfig.Load(c, &cfg); err != nil { logger.Fatal("%s", err) } runInPty := cfg.PTY if runtime.GOOS == "windows" { runInPty = false } bootstrap := &bootstrap.Bootstrap{ Config: bootstrap.Config{ Command: cfg.Command, JobID: cfg.JobID, Repository: cfg.Repository, Commit: cfg.Commit, Branch: cfg.Branch, Tag: cfg.Tag, RefSpec: cfg.RefSpec, Plugins: cfg.Plugins, GitSubmodules: cfg.GitSubmodules, PullRequest: cfg.PullRequest, GitCloneFlags: cfg.GitCloneFlags, GitCleanFlags: cfg.GitCleanFlags, AgentName: cfg.AgentName, PipelineProvider: cfg.PipelineProvider, PipelineSlug: cfg.PipelineSlug, OrganizationSlug: cfg.OrganizationSlug, AutomaticArtifactUploadPaths: cfg.AutomaticArtifactUploadPaths, ArtifactUploadDestination: cfg.ArtifactUploadDestination, CleanCheckout: cfg.CleanCheckout, BuildPath: cfg.BuildPath, BinPath: cfg.BinPath, HooksPath: cfg.HooksPath, PluginsPath: cfg.PluginsPath, Debug: cfg.Debug, RunInPty: runInPty, CommandEval: cfg.CommandEval, PluginsEnabled: cfg.PluginsEnabled, LocalHooksEnabled: cfg.LocalHooksEnabled, SSHKeyscan: cfg.SSHKeyscan, Shell: cfg.Shell, }, } os.Exit(bootstrap.Start()) }, }
View Source
var BootstrapHelpDescription = `` /* 427-byte string literal not displayed */
View Source
var DebugFlag = cli.BoolFlag{
Name: "debug",
Usage: "Enable debug mode",
EnvVar: "BUILDKITE_AGENT_DEBUG",
}
View Source
var DebugHTTPFlag = cli.BoolFlag{
Name: "debug-http",
Usage: "Enable HTTP debug mode, which dumps all request and response bodies to the log",
EnvVar: "BUILDKITE_AGENT_DEBUG_HTTP",
}
View Source
var DownloadHelpDescription = `` /* 954-byte string literal not displayed */
View Source
var EndpointFlag = cli.StringFlag{ Name: "endpoint", Value: DefaultEndpoint, Usage: "The Agent API endpoint", EnvVar: "BUILDKITE_AGENT_ENDPOINT", }
View Source
var ExperimentsFlag = cli.StringSliceFlag{ Name: "experiment", Value: &cli.StringSlice{}, Usage: "Enable experimental features within the buildkite-agent", EnvVar: "BUILDKITE_AGENT_EXPERIMENT", }
View Source
var MetaDataExistsCommand = cli.Command{ Name: "exists", Usage: "Check to see if the meta data key exists for a build", Description: MetaDataExistsHelpDescription, Flags: []cli.Flag{ cli.StringFlag{ Name: "job", Value: "", Usage: "Which job should the meta-data be checked for", EnvVar: "BUILDKITE_JOB_ID", }, AgentAccessTokenFlag, EndpointFlag, NoColorFlag, DebugFlag, DebugHTTPFlag, }, Action: func(c *cli.Context) { cfg := MetaDataExistsConfig{} if err := cliconfig.Load(c, &cfg); err != nil { logger.Fatal("%s", err) } HandleGlobalFlags(cfg) client := agent.APIClient{ Endpoint: cfg.Endpoint, Token: cfg.AgentAccessToken, }.Create() // Find the meta data value var err error var exists *api.MetaDataExists var resp *api.Response err = retry.Do(func(s *retry.Stats) error { exists, resp, err = client.MetaData.Exists(cfg.Job, cfg.Key) if resp != nil && (resp.StatusCode == 401 || resp.StatusCode == 404) { s.Break() } if err != nil { logger.Warn("%s (%s)", err, s) } return err }, &retry.Config{Maximum: 10, Interval: 5 * time.Second}) if err != nil { logger.Fatal("Failed to see if meta-data exists: %s", err) } if !exists.Exists { os.Exit(100) } }, }
View Source
var MetaDataExistsHelpDescription = `` /* 265-byte string literal not displayed */
View Source
var MetaDataGetCommand = cli.Command{ Name: "get", Usage: "Get data from a build", Description: MetaDataGetHelpDescription, Flags: []cli.Flag{ cli.StringFlag{ Name: "default", Value: "", Usage: "If the meta-data value doesn't exist return this instead", }, cli.StringFlag{ Name: "job", Value: "", Usage: "Which job should the meta-data be retrieved from", EnvVar: "BUILDKITE_JOB_ID", }, AgentAccessTokenFlag, EndpointFlag, NoColorFlag, DebugFlag, DebugHTTPFlag, }, Action: func(c *cli.Context) { cfg := MetaDataGetConfig{} if err := cliconfig.Load(c, &cfg); err != nil { logger.Fatal("%s", err) } HandleGlobalFlags(cfg) client := agent.APIClient{ Endpoint: cfg.Endpoint, Token: cfg.AgentAccessToken, }.Create() // Find the meta data value var metaData *api.MetaData var err error var resp *api.Response err = retry.Do(func(s *retry.Stats) error { metaData, resp, err = client.MetaData.Get(cfg.Job, cfg.Key) if resp != nil && (resp.StatusCode == 401 || resp.StatusCode == 404 || resp.StatusCode == 400) { s.Break() return err } if err != nil { logger.Warn("%s (%s)", err, s) } return err }, &retry.Config{Maximum: 10, Interval: 5 * time.Second}) if err != nil { if resp.StatusCode == 404 && c.IsSet("default") { logger.Warn("No meta-data value exists with key `%s`, returning the supplied default \"%s\"", cfg.Key, cfg.Default) fmt.Print(cfg.Default) return } else { logger.Fatal("Failed to get meta-data: %s", err) } } fmt.Print(metaData.Value) }, }
View Source
var MetaDataGetHelpDescription = `` /* 171-byte string literal not displayed */
View Source
var MetaDataSetCommand = cli.Command{ Name: "set", Usage: "Set data on a build", Description: MetaDataSetHelpDescription, Flags: []cli.Flag{ cli.StringFlag{ Name: "job", Value: "", Usage: "Which job should the meta-data be set on", EnvVar: "BUILDKITE_JOB_ID", }, AgentAccessTokenFlag, EndpointFlag, NoColorFlag, DebugFlag, DebugHTTPFlag, }, Action: func(c *cli.Context) { cfg := MetaDataSetConfig{} if err := cliconfig.Load(c, &cfg); err != nil { logger.Fatal("%s", err) } HandleGlobalFlags(cfg) if len(c.Args()) < 2 { logger.Info("Reading meta-data value from STDIN") input, err := ioutil.ReadAll(os.Stdin) if err != nil { logger.Fatal("Failed to read from STDIN: %s", err) } cfg.Value = string(input) } client := agent.APIClient{ Endpoint: cfg.Endpoint, Token: cfg.AgentAccessToken, }.Create() metaData := &api.MetaData{ Key: cfg.Key, Value: cfg.Value, } err := retry.Do(func(s *retry.Stats) error { resp, err := client.MetaData.Set(cfg.Job, metaData) if resp != nil && (resp.StatusCode == 401 || resp.StatusCode == 404) { s.Break() } if err != nil { logger.Warn("%s (%s)", err, s) } return err }, &retry.Config{Maximum: 10, Interval: 5 * time.Second}) if err != nil { logger.Fatal("Failed to set meta-data: %s", err) } }, }
View Source
var MetaDataSetHelpDescription = `` /* 444-byte string literal not displayed */
View Source
var NoColorFlag = cli.BoolFlag{
Name: "no-color",
Usage: "Don't show colors in logging",
EnvVar: "BUILDKITE_AGENT_NO_COLOR",
}
View Source
var PipelineUploadCommand = cli.Command{ Name: "upload", Usage: "Uploads a description of a build pipeline adds it to the currently running build after the current job.", Description: PipelineUploadHelpDescription, Flags: []cli.Flag{ cli.BoolFlag{ Name: "replace", Usage: "Replace the rest of the existing pipeline with the steps uploaded. Jobs that are already running are not removed.", EnvVar: "BUILDKITE_PIPELINE_REPLACE", }, cli.StringFlag{ Name: "job", Value: "", Usage: "The job that is making the changes to it's build", EnvVar: "BUILDKITE_JOB_ID", }, cli.BoolFlag{ Name: "dry-run", Usage: "Rather than uploading the pipeline, it will be echoed to stdout", EnvVar: "BUILDKITE_PIPELINE_UPLOAD_DRY_RUN", }, cli.BoolFlag{ Name: "no-interpolation", Usage: "Skip variable interpolation the pipeline when uploaded", EnvVar: "BUILDKITE_PIPELINE_NO_INTERPOLATION", }, AgentAccessTokenFlag, EndpointFlag, NoColorFlag, DebugFlag, DebugHTTPFlag, }, Action: func(c *cli.Context) { cfg := PipelineUploadConfig{} loader := cliconfig.Loader{CLI: c, Config: &cfg} if err := loader.Load(); err != nil { logger.Fatal("%s", err) } HandleGlobalFlags(cfg) // Find the pipeline file either from STDIN or the first // argument var input []byte var err error var filename string if cfg.FilePath != "" { logger.Info("Reading pipeline config from \"%s\"", cfg.FilePath) filename = filepath.Base(cfg.FilePath) input, err = ioutil.ReadFile(cfg.FilePath) if err != nil { logger.Fatal("Failed to read file: %s", err) } } else if stdin.IsReadable() { logger.Info("Reading pipeline config from STDIN") input, err = ioutil.ReadAll(os.Stdin) if err != nil { logger.Fatal("Failed to read from STDIN: %s", err) } } else { logger.Info("Searching for pipeline config...") paths := []string{ "buildkite.yml", "buildkite.yaml", "buildkite.json", filepath.FromSlash(".buildkite/pipeline.yml"), filepath.FromSlash(".buildkite/pipeline.yaml"), filepath.FromSlash(".buildkite/pipeline.json"), } exists := []string{} for _, path := range paths { if _, err := os.Stat(path); err == nil { exists = append(exists, path) } } if len(exists) > 1 { logger.Fatal("Found multiple configuration files: %s. Please only have 1 configuration file present.", strings.Join(exists, ", ")) } else if len(exists) == 0 { logger.Fatal("Could not find a default pipeline configuration file. See `buildkite-agent pipeline upload --help` for more information.") } found := exists[0] logger.Info("Found config file \"%s\"", found) filename = path.Base(found) input, err = ioutil.ReadFile(found) if err != nil { logger.Fatal("Failed to read file \"%s\" (%s)", found, err) } } if len(input) == 0 { logger.Fatal("Config file is empty") } var parsed interface{} parsed, err = agent.PipelineParser{ Filename: filename, Pipeline: input, NoInterpolation: cfg.NoInterpolation, }.Parse() if err != nil { logger.Fatal("Pipeline parsing of \"%s\" failed (%s)", filename, err) } if cfg.DryRun { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") if err := enc.Encode(parsed); err != nil { logger.Fatal("%#v", err) } os.Exit(0) } if cfg.Job == "" { logger.Fatal("Missing job parameter. Usually this is set in the environment for a Buildkite job via BUILDKITE_JOB_ID.") } if cfg.AgentAccessToken == "" { logger.Fatal("Missing agent-access-token parameter. Usually this is set in the environment for a Buildkite job via BUILDKITE_AGENT_ACCESS_TOKEN.") } client := agent.APIClient{ Endpoint: cfg.Endpoint, Token: cfg.AgentAccessToken, }.Create() uuid := api.NewUUID() err = retry.Do(func(s *retry.Stats) error { _, err = client.Pipelines.Upload(cfg.Job, &api.Pipeline{UUID: uuid, Pipeline: parsed, Replace: cfg.Replace}) if err != nil { logger.Warn("%s (%s)", err, s) if apierr, ok := err.(*api.ErrorResponse); ok && apierr.Response.StatusCode == 422 { logger.Error("Unrecoverable error, skipping retries") s.Break() } } return err }, &retry.Config{Maximum: 5, Interval: 1 * time.Second}) if err != nil { logger.Fatal("Failed to upload and process pipeline: %s", err) } logger.Info("Successfully uploaded and parsed pipeline config") }, }
View Source
var PipelineUploadHelpDescription = `` /* 755-byte string literal not displayed */
View Source
var ShasumHelpDescription = `` /* 926-byte string literal not displayed */
View Source
var StartDescription = `` /* 450-byte string literal not displayed */
View Source
var UploadHelpDescription = `` /* 968-byte string literal not displayed */
Functions ¶
func DefaultConfigFilePaths ¶
func DefaultConfigFilePaths() (paths []string)
func DefaultShell ¶
func DefaultShell() string
func HandleGlobalFlags ¶
func HandleGlobalFlags(cfg interface{})
Types ¶
type AgentStartConfig ¶
type AgentStartConfig struct { Config string `cli:"config"` Token string `cli:"token" validate:"required"` Name string `cli:"name"` Priority string `cli:"priority"` DisconnectAfterJob bool `cli:"disconnect-after-job"` DisconnectAfterJobTimeout int `cli:"disconnect-after-job-timeout"` BootstrapScript string `cli:"bootstrap-script" normalize:"commandpath"` BuildPath string `cli:"build-path" normalize:"filepath" validate:"required"` HooksPath string `cli:"hooks-path" normalize:"filepath"` PluginsPath string `cli:"plugins-path" normalize:"filepath"` Shell string `cli:"shell"` Tags []string `cli:"tags" normalize:"list"` TagsFromEC2 bool `cli:"tags-from-ec2"` TagsFromEC2Tags bool `cli:"tags-from-ec2-tags"` TagsFromGCP bool `cli:"tags-from-gcp"` TagsFromHost bool `cli:"tags-from-host"` WaitForEC2TagsTimeout string `cli:"wait-for-ec2-tags-timeout"` GitCloneFlags string `cli:"git-clone-flags"` GitCleanFlags string `cli:"git-clean-flags"` NoGitSubmodules bool `cli:"no-git-submodules"` NoColor bool `cli:"no-color"` NoSSHKeyscan bool `cli:"no-ssh-keyscan"` NoCommandEval bool `cli:"no-command-eval"` NoLocalHooks bool `cli:"no-local-hooks"` NoPlugins bool `cli:"no-plugins"` NoPTY bool `cli:"no-pty"` TimestampLines bool `cli:"timestamp-lines"` Endpoint string `cli:"endpoint" validate:"required"` Debug bool `cli:"debug"` DebugHTTP bool `cli:"debug-http"` Experiments []string `cli:"experiment" normalize:"list"` /* Deprecated */ NoSSHFingerprintVerification bool `cli:"no-automatic-ssh-fingerprint-verification" deprecated-and-renamed-to:"NoSSHKeyscan"` MetaData []string `cli:"meta-data" deprecated-and-renamed-to:"Tags"` MetaDataEC2 bool `cli:"meta-data-ec2" deprecated-and-renamed-to:"TagsFromEC2"` MetaDataEC2Tags bool `cli:"meta-data-ec2-tags" deprecated-and-renamed-to:"TagsFromEC2Tags"` MetaDataGCP bool `cli:"meta-data-gcp" deprecated-and-renamed-to:"TagsFromGCP"` }
type AnnotateConfig ¶
type AnnotateConfig struct { Body string `cli:"arg:0" label:"annotation body"` Style string `cli:"style"` Context string `cli:"context"` Append bool `cli:"append"` 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"` }
type ArtifactDownloadConfig ¶
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"` }
type ArtifactShasumConfig ¶
type ArtifactShasumConfig struct { Query string `cli:"arg:0" label:"artifact search query" 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"` }
type ArtifactUploadConfig ¶
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"` }
type BootstrapConfig ¶
type BootstrapConfig struct { Command string `cli:"command"` JobID string `cli:"job" validate:"required"` Repository string `cli:"repository" validate:"required"` Commit string `cli:"commit" validate:"required"` Branch string `cli:"branch" validate:"required"` Tag string `cli:"tag"` RefSpec string `cli:"refspec"` Plugins string `cli:"plugins"` PullRequest string `cli:"pullrequest"` GitSubmodules bool `cli:"git-submodules"` SSHKeyscan bool `cli:"ssh-keyscan"` AgentName string `cli:"agent" validate:"required"` OrganizationSlug string `cli:"organization" validate:"required"` PipelineSlug string `cli:"pipeline" validate:"required"` PipelineProvider string `cli:"pipeline-provider" validate:"required"` AutomaticArtifactUploadPaths string `cli:"artifact-upload-paths"` ArtifactUploadDestination string `cli:"artifact-upload-destination"` CleanCheckout bool `cli:"clean-checkout"` GitCloneFlags string `cli:"git-clone-flags"` GitCleanFlags string `cli:"git-clean-flags"` BinPath string `cli:"bin-path" normalize:"filepath"` BuildPath string `cli:"build-path" normalize:"filepath" validate:"required"` HooksPath string `cli:"hooks-path" normalize:"filepath"` PluginsPath string `cli:"plugins-path" normalize:"filepath"` CommandEval bool `cli:"command-eval"` PluginsEnabled bool `cli:"plugins-enabled"` LocalHooksEnabled bool `cli:"local-hooks-enabled"` PTY bool `cli:"pty"` Debug bool `cli:"debug"` Shell string `cli:"shell"` }
type MetaDataExistsConfig ¶
type MetaDataExistsConfig struct { Key string `cli:"arg:0" label:"meta-data key" validate:"required"` 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"` }
type MetaDataGetConfig ¶
type MetaDataGetConfig struct { Key string `cli:"arg:0" label:"meta-data key" validate:"required"` Default string `cli:"default"` 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"` }
type MetaDataSetConfig ¶
type MetaDataSetConfig struct { Key string `cli:"arg:0" label:"meta-data key" validate:"required"` Value string `cli:"arg:1" label:"meta-data value"` 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"` }
type PipelineUploadConfig ¶
type PipelineUploadConfig struct { FilePath string `cli:"arg:0" label:"upload paths"` Replace bool `cli:"replace"` Job string `cli:"job"` AgentAccessToken string `cli:"agent-access-token"` Endpoint string `cli:"endpoint" validate:"required"` DryRun bool `cli:"dry-run"` NoColor bool `cli:"no-color"` NoInterpolation bool `cli:"no-interpolation"` Debug bool `cli:"debug"` DebugHTTP bool `cli:"debug-http"` }
Click to show internal directories.
Click to hide internal directories.