Skip to content

Commit 95799a4

Browse files
andrii-codefreshpasha-codefresh
authored andcommitted
Debug pipeline from cli (#366)
* debug pipeline from cli * bump version * fix argument * test
1 parent b8bafdc commit 95799a4

File tree

7 files changed

+65
-7
lines changed

7 files changed

+65
-7
lines changed

lib/interface/cli/commands/pipeline/pipeline.sdk.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ describe('pipeline', () => {
7474
await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line
7575
});
7676

77+
it('should handle running pipeline in debug mode', async () => {
78+
jest.spyOn(sdk.pipelines, 'debug').mockImplementation();
79+
const argv = { name: 'some name', detach: true };
80+
const pip = new CfPipeline(argv);
81+
await pip.runImpl({ pipelineName: argv.name, options: { debug: true } });
82+
expect(sdk.pipelines.debug).toBeCalled();
83+
sdk.pipelines.debug.mockReset();
84+
});
85+
7786
it('should handle showing logs aaa', async () => {
7887
jest.spyOn(sdk.logs, 'showWorkflowLogs').mockImplementation();
7988
const argv = { name: 'some name' };

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class RunBaseCommand {
2525
const trigger = this.argv['trigger'];
2626
const only = this.argv['only'];
2727
const skip = this.argv['skip'];
28+
const debug = this.argv['debug'];
2829
if (process.env.CF_BUILD_ID) {
2930
this.argv.annotation.push(`cf_predecessor=${process.env.CF_BUILD_ID}`);
3031
}
@@ -46,7 +47,7 @@ class RunBaseCommand {
4647
only,
4748
skip,
4849
annotations,
49-
50+
debug,
5051
},
5152
};
5253
if (variablesFromFile) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ function _buildBody(data) {
6161

6262
class RunExternalCommand extends RunBaseCommand {
6363
async runImpl(request) {
64-
const { pipelineName, options } = request;
65-
this.workflowId = await sdk.pipelines.run({ name: pipelineName }, _buildBody(options));
64+
const { pipelineName, options = {} } = request;
65+
const interfaceMethod = options.debug ? 'debug' : 'run';
66+
this.workflowId = await sdk.pipelines[interfaceMethod]({ name: pipelineName }, _buildBody(options));
6667
if (this.executionRequests.length === 1) {
6768
if (this.argv.detach) {
6869
console.log(this.workflowId);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ const run = new Command({
9696
describe: 'skip specifc steps',
9797
array: true
9898
})
99+
.option('debug', {
100+
describe: 'debug mode',
101+
})
99102
.example('codefresh run PIPELINE_ID | PIPELINE_NAME -trigger TRIGGER_ID | TRIGGER_NAME -b=master', 'Choosing a specific trigger')
100103
.example('codefresh run PIPELINE_ID | PIPELINE_NAME -b=master', 'Defining the source control context using a branch')
101104
.example('codefresh run PIPELINE_ID | PIPELINE_NAME -s=52b992e783d2f84dd0123c70ac8623b4f0f938d1', 'Defining the source control context using a commit')

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class RunLocalCommand extends RunBaseCommand {
7171
async runImpl(request) {
7272
const { pipelineName } = request;
7373
const {
74-
branch, userYamlDescriptor, variables, noCache, resetVolume, noCfCache, enableNotifications, trigger,
74+
branch, userYamlDescriptor, variables, noCache, resetVolume, noCfCache, enableNotifications, trigger, debug,
7575
} = request.options;
7676
const localVolume = this.argv['local-volume'] === true ?
7777
path.join(DEFAULTS.CODEFRESH_PATH, pipelineName) : this.argv['local-volume'];
@@ -113,10 +113,12 @@ class RunLocalCommand extends RunBaseCommand {
113113
console.log(`Running pipeline: ${pipelineName}`);
114114

115115
return new Promise((resolve, reject) => {
116-
const eventEmitter = this.docker.run(DEFAULTS.ENGINE_IMAGE, [], undefined, _.mergeWith({
116+
const eventEmitter = this.docker.run(DEFAULTS.ENGINE_IMAGE, [], undefined, _.mergeWith({
117117
Env: [
118+
...(debug ? ['PIPELINE_DEBUG_MODE=true'] : []),
118119
`ACCESS_TOKEN=${currentContext.token}`,
119-
`PIPELINE_ID=${pipelineName}`, `BRANCH=${branch}`,
120+
`PIPELINE_ID=${pipelineName}`,
121+
`BRANCH=${branch}`,
120122
`CF_HOST=${currentContext.url}`,
121123
'DOCKER_SOCKET_PATH=/var/run/docker.sock',
122124
],

openapi.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5320,6 +5320,48 @@
53205320
"x-sdk-interface": "pipelines.run"
53215321
}
53225322
},
5323+
"/pipelines/debug/{name}": {
5324+
"post": {
5325+
"responses": {
5326+
"200": {
5327+
"description": "ok",
5328+
"headers": {
5329+
"Location": {
5330+
"schema": {
5331+
"type": "string"
5332+
},
5333+
"description": "Endpoint to query the build status"
5334+
}
5335+
}
5336+
}
5337+
},
5338+
"tags": [
5339+
"pipelines"
5340+
],
5341+
"operationId": "pipelines-debug",
5342+
"parameters": [
5343+
{
5344+
"in": "path",
5345+
"name": "name",
5346+
"schema": {
5347+
"type": "string"
5348+
},
5349+
"required": true
5350+
}
5351+
],
5352+
"requestBody": {
5353+
"content": {
5354+
"application/json": {
5355+
"schema": {
5356+
"type": "object"
5357+
}
5358+
}
5359+
}
5360+
},
5361+
"summary": "Debug",
5362+
"x-sdk-interface": "pipelines.debug"
5363+
}
5364+
},
53235365
"/pipelines/yaml/validator": {
53245366
"post": {
53255367
"responses": {

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.35.0",
3+
"version": "0.36.0",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)