-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild.js
More file actions
61 lines (46 loc) · 1.89 KB
/
Copy pathcloudbuild.js
File metadata and controls
61 lines (46 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
const {google} = require('googleapis');
const cloudbuild = google.cloudbuild('v1');
const triggers = cloudbuild.projects.triggers;
async function main () {
// The `getClient` method will choose a service based authentication model
const auth = await google.auth.getClient({
// Scopes can be specified either as an array or as a single, space-delimited string.
scopes: ['https://www.googleapis.com/auth/cloud-platform']
});
// Set the current project Id, obtain automatically is not set in argument
console.log('Project Id argument is: '+process.argv[3]);
var projectSelector;
if (process.argv[3] == undefined) {
console.log(".... A")
projectSelector = await google.auth.getDefaultProjectId();
} else {
console.log(".... B")
projectSelector = process.argv[3];
}
const project = projectSelector;
console.log('Project Id used is: '+project);
// Setup a resuable object for method calls
const creds = { projectId: project, auth };
// Get the list of build triggers
//const trig = await triggers.list(creds);
//console.log(trig.data);
//const trigger = 'e50d68ee-819b-41f7-842e-6fa6a6b632f1';
const trigger = process.argv[2];
const repoSource = {
// "projectId": string,
// "repoName": string,
// "dir": string,
// Union field revision can be only one of the following:
branchName: 'master',
// "tagName": string,
// "commitSha": string,
// End of list of possible types for union field revision.
}
//const runTrig = await triggers.run(Object.assign({triggerId: 'e6ca4a7e-a9a4-4955-9c75-51208a27dd88'}, creds));
const runTrig = await triggers.run({projectId: project, triggerId: trigger, auth, resource: repoSource});
console.log(runTrig);
//const getTrig = await triggers.get({projectId: project, triggerId: trigger, auth});
//console.log(getTrig.data);
}
main().catch(console.error);