Пример #1
0
func (n *GitLabClient) GetBuild(config common.RunnerConfig) (*common.GetBuildResponse, bool) {
	request := common.GetBuildRequest{
		Info:  n.getRunnerVersion(config),
		Token: config.Token,
	}

	var response common.GetBuildResponse
	result, statusText, certificates := n.doJSON(config.RunnerCredentials, "POST", "builds/register.json", 201, &request, &response)

	switch result {
	case 201:
		config.Log().WithFields(logrus.Fields{
			"build":    strconv.Itoa(response.ID),
			"repo_url": response.RepoCleanURL(),
		}).Println("Checking for builds...", "received")
		response.TLSCAChain = certificates
		return &response, true
	case 403:
		config.Log().Errorln("Checking for builds...", "forbidden")
		return nil, false
	case 204, 404:
		config.Log().Debugln("Checking for builds...", "nothing")
		return nil, true
	case clientError:
		config.Log().WithField("status", statusText).Errorln("Checking for builds...", "error")
		return nil, false
	default:
		config.Log().WithField("status", statusText).Warningln("Checking for builds...", "failed")
		return nil, true
	}
}
Пример #2
0
func (c *ExecCommand) parseYaml(job string, build *common.GetBuildResponse) error {
	data, err := ioutil.ReadFile(".gitlab-ci.yml")
	if err != nil {
		return err
	}

	build.Name = job

	// parse gitlab-ci.yml
	config := make(common.BuildOptions)
	err = yaml.Unmarshal(data, config)
	if err != nil {
		return err
	}

	err = config.Sanitize()
	if err != nil {
		return err
	}

	// get job
	jobConfig, ok := config.GetSubOptions(job)
	if !ok {
		return fmt.Errorf("no job named %q", job)
	}

	build.Commands, err = c.buildCommands(config["before_script"], jobConfig["script"])
	if err != nil {
		return err
	}

	build.Variables, err = c.buildGlobalAndJobVariables(config["variables"], jobConfig["variables"])
	if err != nil {
		return err
	}

	build.Options, err = c.buildOptions(config, jobConfig)
	if err != nil {
		return err
	}

	if stage, ok := jobConfig.GetString("stage"); ok {
		build.Stage = stage
	} else {
		build.Stage = "test"
	}
	return nil
}