pythongoogle-cloud-platformgoogle-cloud-build

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.


Solution

  • 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.