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

cloudbuild: invoke build or trigger via cloud build repository (2nd gen) #9029

Open
sano307 opened this issue Nov 17, 2023 · 2 comments
Open
Assignees
Labels
api: cloudbuild Issues related to the Cloud Build API. external This issue is blocked on a bug with the actual product. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@sano307
Copy link

sano307 commented Nov 17, 2023

Is your feature request related to a problem? Please describe.

The part that runs cloud build requests and trigger requests using the second generation of the cloud build repository is missing.

Describe the solution you'd like

The following components must be implemented.

  • cloudbuildpb
    • Source_ConnectedRepository
    • ConnectedRepository
    • ConnectedRepository_Revision

Google Cloud API

Describe alternatives you've considered

e.g.

package test

import (
	"fmt"
	"log"
	"net/http"
	"time"

	cloudbuild "cloud.google.com/go/cloudbuild/apiv1"
	cloudbuildpb "cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb"
	"github.com/GoogleCloudPlatform/functions-framework-go/functions"
)

const (
	projectId    = "test-kim"
	location     = "asia-northeast1"
	connectionId = "test-connection"
	repositoryId = "test-repository"
)

func init() {
	functions.HTTP("ReceiveRequest", ReceiveRequest)
}

func ReceiveRequest(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()

	c, err := cloudbuild.NewClient(ctx)
	if err != nil {
		log.Println(err)
		return
	}
	defer c.Close()

	req := &cloudbuildpb.CreateBuildRequest{
		Parent:    fmt.Sprintf("project/%s/locations/%s", projectId, location),
		ProjectId: projectId,
		Build: &cloudbuildpb.Build{
			Source: &cloudbuildpb.Source{
				Source: &cloudbuildpb.Source_ConnectedRepository{
					ConnectedRepository: &cloudbuildpb.ConnectedRepository{
						Repository: fmt.Sprintf("projects/%s/locations/%s/connections/%s/repositories/%s", projectId, location, connectionId, repositoryId),
						Revision: &cloudbuildpb.ConnectedRepository_Revision{
							Revision: "main",
						},
					},
				},
			},
			Steps: []*cloudbuildpb.BuildStep{
				{
					Name: "ubuntu",
					Args: []string{"echo", "hello", "world"},
				},
			},
		},
	}

	op, err := c.CreateBuild(ctx, req)
	if err != nil {
		log.Println(err)
		return
	}

	for {
		if op.Done {
			break
		}

		time.Sleep(5 * time.Second)
	}

	log.Println("Succeeded")
}
@sano307 sano307 added the triage me I really want to be triaged. label Nov 17, 2023
@product-auto-label product-auto-label bot added the api: cloudbuild Issues related to the Cloud Build API. label Nov 17, 2023
@codyoss
Copy link
Member

codyoss commented Nov 17, 2023

@sano307 Thanks for the feedback. It appears that the public source of truth for this definition has not been updated yet. I will report this to the team so they can publish their new schema. I filed an internal bug: 311649534. I will leave this issue for now for tracking purposes.

@codyoss codyoss added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Nov 17, 2023
@codyoss codyoss self-assigned this Nov 17, 2023
@codyoss codyoss removed the triage me I really want to be triaged. label Nov 17, 2023
@codyoss codyoss added the external This issue is blocked on a bug with the actual product. label Apr 8, 2024
@codyoss
Copy link
Member

codyoss commented Apr 16, 2024

This should be rolling out in the next couple of weeks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: cloudbuild Issues related to the Cloud Build API. external This issue is blocked on a bug with the actual product. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

2 participants