diff --git a/lib/interface/cli/commands/trigger/create.cmd.js b/lib/interface/cli/commands/trigger/create.cmd.js index ed5518961..cb3e6f4fc 100644 --- a/lib/interface/cli/commands/trigger/create.cmd.js +++ b/lib/interface/cli/commands/trigger/create.cmd.js @@ -1,7 +1,8 @@ require('debug')('codefresh:cli:create:trigger'); const Command = require('../../Command'); -const createRoot = require('../root/create.cmd') +const createRoot = require('../root/create.cmd'); +const { prepareKeyValueFromCLIEnvOption } = require('../../helpers/general'); const { trigger } = require('../../../../logic').api; const command = new Command({ @@ -16,6 +17,10 @@ const command = new Command({ }, builder: (yargs) => { yargs + .option('filter', { + describe: 'trigger filter `name=condition` pairs', + default: [], + }) .positional('event-uri', { describe: '`trigger-event` URI', require: true, @@ -31,7 +36,8 @@ const command = new Command({ const pipeline = argv.pipeline; const eventURI = argv['event-uri']; /* eslint-enable prefer-destructuring */ - await trigger.createTrigger(eventURI, pipeline); + const filters = prepareKeyValueFromCLIEnvOption(argv.filter); + await trigger.createTrigger(eventURI, pipeline, filters); console.log(`Trigger: ${eventURI} was successfully linked to the pipeline: ${pipeline}`); }, }); diff --git a/lib/logic/api/trigger.js b/lib/logic/api/trigger.js index 53f2ce85f..746cadedb 100644 --- a/lib/logic/api/trigger.js +++ b/lib/logic/api/trigger.js @@ -28,6 +28,7 @@ const _extractTriggerEventEntity = triggerEvent => ({ const _extractTriggerEntity = trigger => ({ event: trigger.event, pipeline: trigger.pipeline, + filters: trigger.filters, }); // TRIGGER TYPES @@ -114,10 +115,13 @@ const getEventTriggers = async (event) => { return triggers; }; -const createTrigger = async (event, pipeline) => { +const createTrigger = async (event, pipeline, filters) => { const options = { url: `/api/hermes/triggers/${event.replace('/', '_slash_')}/${pipeline}`, method: 'POST', + body: { + filters, + }, }; return sendHttpRequest(options); diff --git a/package.json b/package.json index 76b7ae809..82c160647 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codefresh", - "version": "0.8.40", + "version": "0.8.41", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true,