Skip to content

Commit

Permalink
Remove configuration option for env file, always write it
Browse files Browse the repository at this point in the history
  • Loading branch information
DazWorrall committed Jan 30, 2018
1 parent 877b2b5 commit f7565e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
1 change: 0 additions & 1 deletion agent/agent_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ type AgentConfiguration struct {
RunInPty bool
TimestampLines bool
DisconnectAfterJob bool
WriteEnvFile bool
DisconnectAfterJobTimeout int
}
23 changes: 10 additions & 13 deletions agent/job_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,12 @@ func (r JobRunner) Create() (runner *JobRunner, err error) {
// the Buildkite Agent API
runner.logStreamer = LogStreamer{MaxChunkSizeBytes: r.Job.ChunksMaxSizeBytes, Callback: r.onUploadChunk}.New()

// If configured to write the job env to a file, create that file
if runner.AgentConfiguration.WriteEnvFile {
if file, err := ioutil.TempFile("", fmt.Sprintf("job-env-%s", runner.Job.ID)) ; err != nil {
return runner, err
} else {
logger.Debug("[JobRunner] Created env file: %s", file.Name())
runner.envFile = file
}
// Prepare a file to recieve the given job environment
if file, err := ioutil.TempFile("", fmt.Sprintf("job-env-%s", runner.Job.ID)) ; err != nil {
return runner, err
} else {
logger.Debug("[JobRunner] Created env file: %s", file.Name())
runner.envFile = file
}

// The process that will run the bootstrap script
Expand Down Expand Up @@ -148,9 +146,8 @@ func (r *JobRunner) Run() error {
if r.envFile != nil {
if err := os.Remove(r.envFile.Name()); err != nil {
logger.Warn("[JobRunner] Error cleaning up env file: %s", err)
} else {
logger.Debug("[JobRunner] Deleted env file: %s", r.envFile.Name())
}
logger.Debug("[JobRunner] Deleted env file: %s", r.envFile.Name())
}

logger.Info("Finished job %s", r.Job.ID)
Expand Down Expand Up @@ -187,9 +184,9 @@ func (r *JobRunner) createEnvironment() []string {
env[key] = value
}

// Write out the job environment to a file if configured, in k=v format.
// We do this early to present only the clean environment, i.e excluding
// any varibales set or inherited here.
// Write out the job environment to a file, in k=v format.
// We present only the clean environment - i.e only variables configured
// on the job upstream - and expose the path in another environment variable.
if r.envFile != nil {
for key, value := range(env) {
r.envFile.WriteString(fmt.Sprintf("%s=%s\n", key, value))
Expand Down
7 changes: 0 additions & 7 deletions clicommand/agent_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ type AgentStartConfig struct {
Debug bool `cli:"debug"`
DebugHTTP bool `cli:"debug-http"`
Experiments []string `cli:"experiment"`
WriteEnvFile bool `cli:"write-env-file"`
/* Deprecated */
MetaData []string `cli:"meta-data" deprecated-and-renamed-to:"Tags"`
MetaDataEC2 bool `cli:"meta-data-ec2" deprecated-and-renamed-to:"TagsFromEC2"`
Expand Down Expand Up @@ -219,11 +218,6 @@ var AgentStartCommand = cli.Command{
Usage: "Don't allow this agent to load plugins",
EnvVar: "BUILDKITE_NO_PLUGINS",
},
cli.BoolFlag{
Name: "write-env-file",
Usage: "Write the environment variables given for a job to a file",
EnvVar: "BUILDKITE_WRITE_ENV_FILE",
},
ExperimentsFlag,
EndpointFlag,
NoColorFlag,
Expand Down Expand Up @@ -322,7 +316,6 @@ var AgentStartCommand = cli.Command{
TimestampLines: cfg.TimestampLines,
DisconnectAfterJob: cfg.DisconnectAfterJob,
DisconnectAfterJobTimeout: cfg.DisconnectAfterJobTimeout,
WriteEnvFile: cfg.WriteEnvFile,
},
}

Expand Down

0 comments on commit f7565e3

Please sign in to comment.