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

return execution id on pipeline execute command #264

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/pipeline/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func executePipeline(cmd *cobra.Command, options *executeOptions) error {
}
}

resp, err := options.GateClient.PipelineControllerApi.InvokePipelineConfigUsingPOST1(options.GateClient.Context,
successPayload, resp, err := options.GateClient.PipelineControllerApi.InvokePipelineConfigUsingPOST1(options.GateClient.Context,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing the JSON decoding in the generated file, why not attempt a JSON decode of the response body resp here?

Copy link
Contributor

@karlskewes karlskewes Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it might be better to use the newer Gate API options.GateClient.PipelineControllerApi.InvokePipelineConfigViaEchoUsingPOST instead.

This returns an interface{} which we can marshal into a new struct, e.g: type executedPipelines struct {...} and then log out.
The struct will hold a list of executed pipelines because a single trigger (spin's POST) can invoke multiple pipelines.

See Gate groovy returned object which would land in the Go empty interface.

    return [
      eventId: eventId,
      ref    : String.format("/pipelines/%s", executionId)
    ]

Per: https://github.com/spinnaker/gate/blob/6e751aa7d7c9a4f116b85b6f4b73d5203d902ce7/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/PipelineService.groovy#L94-L116

options.application,
options.name,
map[string]interface{}{"trigger": trigger})
Expand All @@ -100,7 +100,7 @@ func executePipeline(cmd *cobra.Command, options *executeOptions) error {
return fmt.Errorf("Encountered an error executing pipeline, status code: %d\n", resp.StatusCode)
}

options.Ui.Success("Pipeline execution started")
options.Ui.JsonOutput(successPayload)

return nil
}
26 changes: 15 additions & 11 deletions gateapi/pipeline_controller_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,13 @@ func (a *PipelineControllerApiService) GetPipelineUsingGET(ctx context.Context,
@param optional (nil or map[string]interface{}) with one or more of:
@param "trigger" (interface{}) trigger
@return */
func (a *PipelineControllerApiService) InvokePipelineConfigUsingPOST1(ctx context.Context, application string, pipelineNameOrId string, localVarOptionals map[string]interface{}) ( *http.Response, error) {
func (a *PipelineControllerApiService) InvokePipelineConfigUsingPOST1(ctx context.Context, application string, pipelineNameOrId string, localVarOptionals map[string]interface{}) (interface{}, *http.Response, error) {
var (
localVarHttpMethod = strings.ToUpper("Post")
localVarPostBody interface{}
localVarFileName string
localVarFileBytes []byte
localVarPostBody interface{}
localVarFileName string
localVarFileBytes []byte
successPayload interface{}
)

// create path and map variables
Expand All @@ -595,9 +596,8 @@ func (a *PipelineControllerApiService) InvokePipelineConfigUsingPOST1(ctx contex
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}


// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", }
localVarHttpContentTypes := []string{"application/json"}

// set Content-Type header
localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
Expand All @@ -608,7 +608,7 @@ func (a *PipelineControllerApiService) InvokePipelineConfigUsingPOST1(ctx contex
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"*/*",
}
}

// set Accept header
localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
Expand All @@ -621,20 +621,24 @@ func (a *PipelineControllerApiService) InvokePipelineConfigUsingPOST1(ctx contex
}
r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
if err != nil {
return nil, err
return successPayload, nil, err
}

localVarHttpResponse, err := a.client.callAPI(r)
if err != nil || localVarHttpResponse == nil {
return localVarHttpResponse, err
return successPayload, localVarHttpResponse, err
}
defer localVarHttpResponse.Body.Close()
if localVarHttpResponse.StatusCode >= 300 {
bodyBytes, _ := ioutil.ReadAll(localVarHttpResponse.Body)
return localVarHttpResponse, reportError("Status: %v, Body: %s", localVarHttpResponse.Status, bodyBytes)
return successPayload, localVarHttpResponse, reportError("Status: %v, Body: %s", localVarHttpResponse.Status, bodyBytes)
}

return localVarHttpResponse, err
if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
return successPayload, localVarHttpResponse, err
}
Comment on lines +637 to +639
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be moved to execute.go per my comment above.
Then do a pass to ensure errors are checked and resp.Body is closed, etc.


return successPayload, localVarHttpResponse, err
}

/* PipelineControllerApiService Trigger a pipeline execution
Expand Down