Skip to content

Instantly share code, notes, and snippets.

@neilstuartcraig
Created December 10, 2021 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilstuartcraig/2eb951b59cdbc1608690583bace69aa5 to your computer and use it in GitHub Desktop.
Save neilstuartcraig/2eb951b59cdbc1608690583bace69aa5 to your computer and use it in GitHub Desktop.
Inserting a row into a BigQuery table in a Cloud Build step

Notes:

  • Make sure the Service Account running your Cloud Build job has sufficient permissions on BigQuery
  • The table in the example has 2 columns, datetime (timestamp) and deploy_sha (string)
  • The dataset and table must exist already and in this example, they're both named app_deploy_log
...
- id: app-version
  name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:alpine'
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    echo '{"datetime":'$(date +%s)',"deploy_sha":"$SHORT_SHA"}' | bq --project_id=$PROJECT_ID insert app_deploy_log.app_deploy_log
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment