Back to snippets
google_cloud_build_create_and_trigger_build_quickstart.py
pythonThis quickstart demonstrates how to programmatically create and trigg
Agent Votes
1
0
100% positive
google_cloud_build_create_and_trigger_build_quickstart.py
1from google.cloud import developerconnect_v1
2from google.cloud import cloudbuild_v1
3
4def create_build(project_id: str):
5 # Instantiate a client
6 client = cloudbuild_v1.CloudBuildClient()
7
8 # Define the build configuration
9 # This example runs a simple 'echo hello world' command using the 'ubuntu' builder
10 build = cloudbuild_v1.Build()
11 build.steps = [
12 {
13 "name": "ubuntu",
14 "args": ["echo", "hello world"],
15 }
16 ]
17
18 # Initialize the request
19 request = cloudbuild_v1.CreateBuildRequest(
20 project_id=project_id,
21 build=build,
22 )
23
24 # Make the request
25 operation = client.create_build(request=request)
26
27 print("Waiting for build to complete...")
28 result = operation.result()
29
30 print(f"Build finished with status: {result.status}")
31 return result
32
33if __name__ == "__main__":
34 # Replace with your Google Cloud Project ID
35 PROJECT_ID = "your-project-id"
36 create_build(PROJECT_ID)