Skip to content

Commit

Permalink
add flag --context to run pipeline command
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Sucharevich authored Feb 13, 2018
1 parent fab257b commit e4a35a8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
11 changes: 9 additions & 2 deletions lib/interface/cli/commands/pipeline/run.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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()) {
Expand Down Expand Up @@ -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);
}

Expand Down
22 changes: 22 additions & 0 deletions lib/logic/api/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ({
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.8.16",
"version": "0.8.17",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down

0 comments on commit e4a35a8

Please sign in to comment.