Frederick
Frederick

Reputation: 9

CloudBuild pull status from latest run, from a specific build trigger using via CloudBuild API?

UPDATE: Changing the trigger's region from Europe-West-2 to the default, Global Non-Region resulted in the API working as expected.

The end goal of this project is to check the status of the latest run from a specific cloud build trigger in airflow.

However, I'm unable to list a single build, or pull a list of triggers in my project, etc.

None of the examples in the google docs appear to be working for me. For example, pulling a list of triggers from my project:

from google.cloud.devtools import cloudbuild_v1

def sample_list_build_triggers():
    # Create a client
    client = cloudbuild_v1.CloudBuildClient()

    # Initialize request argument(s)
    request = cloudbuild_v1.ListBuildTriggersRequest(
        project_id="example_project_id",
    )

    # Make the request
    page_result = client.list_build_triggers(request=request)

    # Handle the response
    for response in page_result:
        print(response)

sample_list_build_triggers()

This returns None, when there are certainly triggers. The project_id I use here is the exact same as the one from a cloud build's 'execution details' tab. The docs do state that the API is experimental. But perhaps I am missing something? It's quite hard as everything I try silently fails, and there doesn't seem to be a way to error test here.

I have also referenced this question. This is the same example from the google docs shown above that is not working.

Is there an alternative method to retrieving the status of a cloud build run? Or any advice on how to go about testing? I have my CloudBuild trigger being set off by a pubsub message, but I'm not sure how to detect when it runs successfully. Perhaps this could be a potential workaround.

Thanks for any help.

Upvotes: 0

Views: 485

Answers (3)

Piyush Agarwal
Piyush Agarwal

Reputation: 61

There seems to be an issue with CloudBuild API documentation. Referencing the cloudbuild nodejs API that I used:

// Endpoint to fetch build status
app.get('/api/build-status', async (req, res) => {
    const { buildId, projectId } = req.query;
    const location = "europe-west2";
    const requestBuildId = `projects/${projectId}/locations/${location}/builds/${buildId}`;

    const request = {
        name: requestBuildId,
    };

    try {
        const responseData = await cloudBuildClient.getBuild(request);
        console.log("Full responseData:", JSON.stringify(responseData, null, 2));

        res.json(responseData);
    } catch (error) {
        console.error('Error fetching build status:', error);
        res.status(500).json({ error: 'Failed to fetch build status', details: error.message });
    }
});

Upvotes: 0

Frederick
Frederick

Reputation: 9

UPDATE: My triggers were in located Europe-West2.

Google docs here don't indicate API availability across regions. However, I was able to find a workaround by simply placing my triggers in the default global non-region.

I was then able to pull the status via the API as expected with the above code. For anyone facing same issues, just use the global region and the API ought to work.

Upvotes: 0

DominicT
DominicT

Reputation: 355

Since the documentation stated that the API is still in experimental.

You may encounter bugs and errors along the way this would fall under the Pre-GA Offerings Terms.

Pre-GA Offerings Terms. Google may make available to Customer pre-general availability Google Cloud Platform features, services or software that are either not yet listed at https://cloud.google.com/terms/services or identified as “Early Access,” “Alpha,” “Beta,” “Preview,” “Experimental,” or a similar designation in related documentation or materials (collectively, “Pre-GA Offerings”). While Pre-GA Offerings are not Services or Software, Customer’s use of Pre-GA Offerings is subject to the terms of the Agreement applicable to Services (or Software, if applicable), as amended by this Section 5.

The next thing I would suggest is to file a bug under the Issue tracking system and product feature request.

Disclaimer: This doesn't have a specific ETA but you can keep track of its progress once you create the bug.

Upvotes: 1

Related Questions