Exemple #1
0
func (atcConfig ATCConfig) newConfig(configPath flaghelpers.PathFlag, templateVariablesFiles []flaghelpers.PathFlag, templateVariables template.Variables) atc.Config {
	configFile, err := ioutil.ReadFile(string(configPath))
	if err != nil {
		displayhelpers.FailWithErrorf("could not read config file", err)
	}

	var resultVars template.Variables

	for _, path := range templateVariablesFiles {
		fileVars, templateErr := template.LoadVariablesFromFile(string(path))
		if templateErr != nil {
			displayhelpers.FailWithErrorf("failed to load variables from file (%s)", templateErr, string(path))
		}

		resultVars = resultVars.Merge(fileVars)
	}

	resultVars = resultVars.Merge(templateVariables)

	configFile, err = template.Evaluate(configFile, resultVars)
	if err != nil {
		displayhelpers.FailWithErrorf("failed to evaluate variables into template", err)
	}

	var newConfig atc.Config
	err = yaml.Unmarshal(configFile, &newConfig)
	if err != nil {
		displayhelpers.FailWithErrorf("failed to parse configuration file", err)
	}

	return newConfig
}
Exemple #2
0
func (atcConfig ATCConfig) Set(configPath flaghelpers.PathFlag, templateVariables template.Variables, templateVariablesFiles []flaghelpers.PathFlag) {
	newConfig := atcConfig.newConfig(configPath, templateVariablesFiles, templateVariables)
	existingConfig, existingConfigVersion, _, err := atcConfig.Client.PipelineConfig(atcConfig.PipelineName)
	if err != nil {
		displayhelpers.FailWithErrorf("failed to retrieve config", err)
	}

	diff(existingConfig, newConfig)

	if !atcConfig.ApplyConfigInteraction() {
		fmt.Println("bailing out")
		os.Exit(1)
	}

	created, updated, err := atcConfig.Client.CreateOrUpdatePipelineConfig(
		atcConfig.PipelineName,
		existingConfigVersion,
		newConfig,
	)
	if err != nil {
		displayhelpers.FailWithErrorf("failed to update configuration", err)
	}
	atcConfig.showHelpfulMessage(created, updated)
}
Exemple #3
0
func (command *TriggerJobCommand) Execute(args []string) error {
	pipelineName, jobName := command.Job.PipelineName, command.Job.JobName

	client, err := rc.TargetClient(Fly.Target)
	if err != nil {
		return err
	}
	err = rc.ValidateClient(client, Fly.Target)
	if err != nil {
		return err
	}

	_, err = client.CreateJobBuild(pipelineName, jobName)
	if err != nil {
		displayhelpers.FailWithErrorf("pipeline/job '%s/%s' not found\n", err, pipelineName, jobName)
	}
	fmt.Printf("started '%s/%s'\n", pipelineName, jobName)
	return nil
}