Skip to content

Commit e4a35a8

Browse files
author
Oleg Sucharevich
authored
add flag --context to run pipeline command
1 parent fab257b commit e4a35a8

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

lib/interface/cli/commands/pipeline/run.cmd.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ const run = new Command({
5050
alias: 'd',
5151
describe: 'Run pipeline and print build ID',
5252
})
53+
.option('context', {
54+
alias: 'c',
55+
describe: 'Run pipeline with contexts',
56+
default: [],
57+
})
5358
.example('codefresh run PIPELINE_ID -b=master', 'Defining the source control context using a branch')
5459
.example('codefresh run PIPELINE_ID -s=52b992e783d2f84dd0123c70ac8623b4f0f938d1', 'Defining the source control context using a commit')
5560
.example('codefresh run PIPELINE_ID -b=master -v key1=value1 -v key2=value2', 'Setting variables through the command')
56-
.example('codefresh run PIPELINE_ID -b=master --var-file ./var_file.yml', 'Settings variables through a yml file');
61+
.example('codefresh run PIPELINE_ID -b=master --var-file ./var_file.yml', 'Settings variables through a yml file')
62+
.example('codefresh run PIPELINE_ID -b=master --context context', 'Inject contexts to the pipeline execution');
5763

5864
crudFilenameOption(yargs, {
5965
name: 'variable-file',
@@ -70,7 +76,7 @@ const run = new Command({
7076
const noCache = argv['no-cache'];
7177
const resetVolume = argv['reset-volume'];
7278
const variablesFromFile = argv['var-file'];
73-
79+
const contexts = argv['context'];
7480

7581
if (!authManager.getCurrentContext()
7682
.isBetaFeatEnabled()) {
@@ -121,6 +127,7 @@ const run = new Command({
121127
const variables = prepareKeyValueFromCLIEnvOption(argv.variable);
122128
const request = _.cloneDeep(executionRequestTemplate);
123129
request.options.variables = variables;
130+
request.options.contexts = contexts;
124131
executionRequests.push(request);
125132
}
126133

lib/logic/api/pipeline.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ const _ = require('lodash');
22
const { sendHttpRequest } = require('./helper');
33
const Pipeline = require('../entities/Pipeline');
44
const CFError = require('cf-errors');
5+
const {
6+
getContextByName,
7+
} = require('./context');
8+
const Promise = require('bluebird');
59

610

711
const _extractFieldsForPipelineEntity = pipeline => ({
@@ -139,6 +143,24 @@ const runPipelineById = async (id, data = {}) => {
139143
body.sha = data.sha;
140144
}
141145

146+
if (data.contexts) {
147+
let contexts = [];
148+
if (_.isString(data.contexts)) {
149+
contexts = [data.contexts];
150+
}
151+
await Promise.map(data.contexts, async (name) => {
152+
try {
153+
await getContextByName(name);
154+
contexts.push({
155+
name,
156+
});
157+
} catch (err) {
158+
throw new CFError(err, `Failed to verify context ${name} with error ${err.message}`);
159+
}
160+
});
161+
body.contexts = contexts;
162+
}
163+
142164
const options = {
143165
url: `/api/builds/${id}`,
144166
method: 'POST',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.8.16",
3+
"version": "0.8.17",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)