cloudbuild ruby googl
Step 1: Install the required gems
# Add these lines to your Gemfile
gem 'google-cloud-storage', '~> 1.32', require: 'google/cloud/storage'
gem 'google-cloud-build', '~> 0.9', require: 'google/cloud/build'
# Run bundle install to install the gems
Step 2: Set up Google Cloud Build API authentication
# Set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of your service account key JSON file
ENV['GOOGLE_APPLICATION_CREDENTIALS'] = 'path/to/your/keyfile.json'
Step 3: Configure Google Cloud Build client
# Create a new Cloud Build client
require 'google/cloud/build'
build = Google::Cloud::Build.new
Step 4: Create a build trigger
# Define the trigger configuration
trigger = build.create_trigger(
'your-project-id',
'trigger-name',
description: 'Your trigger description',
filename: 'cloudbuild.yaml', # Path to your Cloud Build configuration file
branch_name: 'main', # Branch to trigger the build
substitutions: { _FOO: 'bar' } # Substitutions for variables in your build configuration file
)
Step 5: Start a build using the trigger
# Start a build with the specified trigger ID
build.start_build('your-project-id', 'trigger-id')
Step 6: Monitor the build status
# Get build details by build ID
build_id = 'your-build-id'
build_info = build.get_build('your-project-id', build_id)
# Check the build status
status = build_info.status
puts "Build status: #{status}"
Note: Ensure that you have appropriate permissions and credentials set up in your Google Cloud project for the Cloud Build API and Storage API. Replace placeholder values such as 'your-project-id', 'trigger-name', 'path/to/your/keyfile.json', 'cloudbuild.yaml', 'main', 'your-build-id', etc., with your actual project and configuration details.