From e4a35a839f64bda69543433f6a3bbe0764b70788 Mon Sep 17 00:00:00 2001 From: Oleg Sucharevich Date: Tue, 13 Feb 2018 10:57:44 +0200 Subject: [PATCH] add flag --context to run pipeline command --- .../cli/commands/pipeline/run.cmd.js | 11 ++++++++-- lib/logic/api/pipeline.js | 22 +++++++++++++++++++ package.json | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/interface/cli/commands/pipeline/run.cmd.js b/lib/interface/cli/commands/pipeline/run.cmd.js index 9bddd59b6..67f4f58a7 100644 --- a/lib/interface/cli/commands/pipeline/run.cmd.js +++ b/lib/interface/cli/commands/pipeline/run.cmd.js @@ -50,10 +50,16 @@ const run = new Command({ alias: 'd', describe: 'Run pipeline and print build ID', }) + .option('context', { + alias: 'c', + describe: 'Run pipeline with contexts', + default: [], + }) .example('codefresh run PIPELINE_ID -b=master', 'Defining the source control context using a branch') .example('codefresh run PIPELINE_ID -s=52b992e783d2f84dd0123c70ac8623b4f0f938d1', 'Defining the source control context using a commit') .example('codefresh run PIPELINE_ID -b=master -v key1=value1 -v key2=value2', 'Setting variables through the command') - .example('codefresh run PIPELINE_ID -b=master --var-file ./var_file.yml', 'Settings variables through a yml file'); + .example('codefresh run PIPELINE_ID -b=master --var-file ./var_file.yml', 'Settings variables through a yml file') + .example('codefresh run PIPELINE_ID -b=master --context context', 'Inject contexts to the pipeline execution'); crudFilenameOption(yargs, { name: 'variable-file', @@ -70,7 +76,7 @@ const run = new Command({ const noCache = argv['no-cache']; const resetVolume = argv['reset-volume']; const variablesFromFile = argv['var-file']; - + const contexts = argv['context']; if (!authManager.getCurrentContext() .isBetaFeatEnabled()) { @@ -121,6 +127,7 @@ const run = new Command({ const variables = prepareKeyValueFromCLIEnvOption(argv.variable); const request = _.cloneDeep(executionRequestTemplate); request.options.variables = variables; + request.options.contexts = contexts; executionRequests.push(request); } diff --git a/lib/logic/api/pipeline.js b/lib/logic/api/pipeline.js index ced9aa48a..0232a71b9 100644 --- a/lib/logic/api/pipeline.js +++ b/lib/logic/api/pipeline.js @@ -2,6 +2,10 @@ const _ = require('lodash'); const { sendHttpRequest } = require('./helper'); const Pipeline = require('../entities/Pipeline'); const CFError = require('cf-errors'); +const { + getContextByName, +} = require('./context'); +const Promise = require('bluebird'); const _extractFieldsForPipelineEntity = pipeline => ({ @@ -139,6 +143,24 @@ const runPipelineById = async (id, data = {}) => { body.sha = data.sha; } + if (data.contexts) { + let contexts = []; + if (_.isString(data.contexts)) { + contexts = [data.contexts]; + } + await Promise.map(data.contexts, async (name) => { + try { + await getContextByName(name); + contexts.push({ + name, + }); + } catch (err) { + throw new CFError(err, `Failed to verify context ${name} with error ${err.message}`); + } + }); + body.contexts = contexts; + } + const options = { url: `/api/builds/${id}`, method: 'POST', diff --git a/package.json b/package.json index 93fb0b219..67a72321c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codefresh", - "version": "0.8.16", + "version": "0.8.17", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true,