| 17 | |
| 18 | // [START cloudbuild_quickstart] |
| 19 | async function quickstart( |
| 20 | projectId = 'YOUR_PROJECT_ID', // Your Google Cloud Platform project ID |
| 21 | triggerId = 'YOUR_TRIGGER_ID', // UUID for build trigger. |
| 22 | branchName = 'BRANCH_TO_BUILD' // Branch to run build against. |
| 23 | ) { |
| 24 | // Imports the Google Cloud client library |
| 25 | const {CloudBuildClient} = require('@google-cloud/cloudbuild'); |
| 26 | |
| 27 | // Creates a client |
| 28 | const cb = new CloudBuildClient(); |
| 29 | |
| 30 | // Note: for Private Pools, you'll have to specify an API endpoint value |
| 31 | // For example: |
| 32 | // const cb = new CloudBuildClient({ apiEndpoint: '<YOUR_POOL_REGION>-cloudbuild.googleapis.com' }); |
| 33 | |
| 34 | // Starts a build against the branch provided. |
| 35 | const [resp] = await cb.runBuildTrigger({ |
| 36 | projectId, |
| 37 | triggerId, |
| 38 | source: { |
| 39 | projectId, |
| 40 | dir: './', |
| 41 | branchName, |
| 42 | }, |
| 43 | }); |
| 44 | console.info(`triggered build for ${triggerId}`); |
| 45 | const [build] = await resp.promise(); |
| 46 | |
| 47 | const STATUS_LOOKUP = [ |
| 48 | 'UNKNOWN', |
| 49 | 'Queued', |
| 50 | 'Working', |
| 51 | 'Success', |
| 52 | 'Failure', |
| 53 | 'Error', |
| 54 | 'Timeout', |
| 55 | 'Cancelled', |
| 56 | ]; |
| 57 | for (const step of build.steps) { |
| 58 | console.info( |
| 59 | `step:\n\tname: ${step.name}\n\tstatus: ${STATUS_LOOKUP[build.status]}` |
| 60 | ); |
| 61 | } |
| 62 | } |
| 63 | // [END cloudbuild_quickstart] |
| 64 | |
| 65 | const args = process.argv.slice(2); |