Skip to content

Commit d2c80ba

Browse files
committed
Action and Trigger Plugins: Provide secrets via JSON in top-level secrets object, to be consistent with Event Plugins.
1 parent e5041cb commit d2c80ba

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

docs/plugins.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ When Action Plugins are invoked, they are passed a JSON document on STDIN (compr
422422
| `type` | String | The [Plugin.type](data.md#plugin-type), which will be set to `action`. |
423423
| `condition` | String | The [Action.condition](data.md#action-condition) which activated the Plugin. |
424424
| `params` | Object | If the Plugin defines any parameters, their values will be here. |
425+
| `secrets` | Object | If the Plugin is assigned any [Secrets](secrets.md), they are included here (as well as in environment variables). |
425426
| (Other) | Various | Based on context; see below. |
426427

427428
If the Action Plugin is being invoked in job-related context (i.e. on job start, job complete, or other job actions) the contents of [JobHookData](data.md#jobhookdata) will also be merged in at the top-level. Similarly, if the plugin is being invoked in an alert-related context (alert fired or cleared), then the contents of [AlertHookData](data.md#alerthookdata) will be merged in.
@@ -436,6 +437,10 @@ Here is an example JSON document sent to an Action Plugin's STDIN as part of a j
436437
"params": {
437438
"foo": "Baz"
438439
},
440+
"secrets": {
441+
"DB_USER": "dev",
442+
"DB_PASS": "1234"
443+
},
439444
"job": {
440445
"id": "jmhzaot10tm",
441446
"complete": true,
@@ -612,11 +617,14 @@ When your trigger plugin is invoked, it will be passed an array of all the event
612617
"notes": ""
613618
}
614619
}
615-
]
620+
],
621+
"secrets": {}
616622
}
617623
```
618624

619-
As with all xyOps STDIO communication, the JSON will always have a top-level `xy` property set to `1` (the [xyOps Wire Protocol](xywp.md) version), and a `type` property set to `trigger`. Also present is an `items` array, which will contain an element for each event that has the plugin assigned as a trigger. It is up to your plugin code to decide if each event should launch a job or not. You are also provided some other information about the events:
625+
As with all xyOps STDIO communication, the JSON will always have a top-level `xy` property set to `1` (the [xyOps Wire Protocol](xywp.md) version), and a `type` property set to `trigger`. If your plugin was assigned any secrets, they will be available in the top-level `secrets` object (and also as environment variables).
626+
627+
Also present is an `items` array, which will contain an element for each event that has the plugin assigned as a trigger. It is up to your plugin code to decide if each event should launch a job or not. You are also provided some other information about the events:
620628

621629
| Property Name | Type | Description |
622630
|---------------|------|-------------|

lib/action.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@ class Actions {
10141014

10151015
// grab secrets needed by plugin
10161016
var sec = this.getSecretsForType('plugins', plugin.id);
1017+
hook_args.secrets = sec;
10171018

10181019
var child_opts = {
10191020
cwd: plugin.cwd || os.tmpdir(),

lib/schedule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ class Scheduler {
589589

590590
// Write data to child's stdin
591591
child.stdin.on('error', noop);
592-
child.stdin.write( JSON.stringify({ xy: 1, type: 'trigger', items }) + "\n" );
592+
child.stdin.write( JSON.stringify({ xy: 1, type: 'trigger', items: items, secrets: sec }) + "\n" );
593593
child.stdin.end();
594594
}
595595

0 commit comments

Comments
 (0)