Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argument with boolean value #306

Open
Jarnpher553 opened this issue Oct 13, 2021 · 1 comment
Open

argument with boolean value #306

Jarnpher553 opened this issue Oct 13, 2021 · 1 comment

Comments

@Jarnpher553
Copy link

type Argument struct {
	Description string `json:"desc,omitempty"`
	Type        string `json:"type,omitempty"`
	Key         string `json:"key,omitempty"`
	Value       string `json:"value,omitempty"`
}

func (pp *PipelineProvider) PipelineStart(c echo.Context) error {
	pipelineIDStr := c.Param("pipelineid")

	// Look for arguments.
	// We do not check for errors here cause arguments are optional.
	var args []*gaia.Argument
	_ = c.Bind(&args)

	// Convert string to int because id is int
	pipelineID, err := strconv.Atoi(pipelineIDStr)
	if err != nil {
		return c.String(http.StatusBadRequest, errInvalidPipelineID.Error())
	}

	// Look up pipeline for the given id
	var foundPipeline gaia.Pipeline
	for _, p := range pipeline.GlobalActivePipelines.GetAll() {
		if p.ID == pipelineID {
			foundPipeline = p
			break
		}
	}

	// Overwrite docker setting
	for _, a := range args {
		if a.Key == "docker" {
			foundPipeline.Docker = a.Value == "1"
		}
	}

	if foundPipeline.Name != "" {
		pipelineRun, err := pp.deps.Scheduler.SchedulePipeline(&foundPipeline, gaia.StartReasonManual, args)
		if err != nil {
			return c.String(http.StatusBadRequest, err.Error())
		} else if pipelineRun != nil {
			return c.JSON(http.StatusCreated, pipelineRun)
		}
	}

	// Pipeline not found
	return c.String(http.StatusNotFound, errPipelineNotFound.Error())
}

if bind with []*gaia.Argument can not pass argument with boolean value, the Argument value is type of string

@Skarlso
Copy link
Member

Skarlso commented Oct 13, 2021

Hi!

Thanks for opening an issue.

Yes, everything is string:string in the values, because the protobuf definition defines them as such. So if you need a boolean value, I suggest using "true" or "1" or something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants