Skip to content

Commit c1fcb19

Browse files
Add support for pipeline v2 (#165)
1 parent 7fbc48b commit c1fcb19

File tree

20 files changed

+389
-311
lines changed

20 files changed

+389
-311
lines changed

docs/content/pipelines v2/spec.md renamed to docs/content/pipelines v2 (beta)/spec.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
+++
22
title = "Spec"
3-
weight = 10
43
+++
54

65
A Pipeline needs `.apiVersion`, `.kind`, and `.metadata` fields.
@@ -15,8 +14,12 @@ apiVersion: "v1"
1514
kind: "pipeline"
1615
metadata:
1716
name: "new-pipeline"
17+
description: "my description"
1818
labels:
19-
repo: "github:ArikMaor/ping-server"
19+
repo: "ArikMaor/ping-server"
20+
key1: "value1"
21+
project: "asd"
22+
2023
spec:
2124
triggers:
2225
- type: "scm"
@@ -32,13 +35,25 @@ spec:
3235
value: "BLA BLA"
3336
encrypted: true
3437
steps:
35-
test_step:
38+
clone_step:
39+
repo: github.com/itai-codefresh/test-env-file
40+
revision: master
41+
test_step_1:
3642
image: "alpine"
43+
working_directory: ${{clone_step}}
3744
commands:
45+
- echo ls
3846
- echo "hello world"
3947
- echo "plain value $PORT"
4048
- echo "encrypted value $PAPA"
4149
- echo "value from context $COOKIE"
50+
build:
51+
type: build
52+
working_directory: ${{clone_step}}
53+
dockerfile: ./Dockerfile
54+
image_name: itai/test
55+
tag: bla
56+
4257
```
4358

4459
#### Pipeline which is stored on a remote git
@@ -48,7 +63,7 @@ kind: "pipeline"
4863
metadata:
4964
name: "ew-pipeline-git"
5065
labels:
51-
repo: "github:ArikMaor/ping-server"
66+
repo: "ArikMaor/ping-server"
5267
spec:
5368
triggers:
5469
- type: "scm"
@@ -76,7 +91,7 @@ kind: "pipeline"
7691
metadata:
7792
name: "new-pipeline-url"
7893
labels:
79-
repo: "github:codefresh-io/cli"
94+
repo: "codefresh-io/cli"
8095
spec:
8196
triggers:
8297
- type: "scm"

docs/content/pipelines v2/_index.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ const CFError = require('cf-errors');
1010

1111
const TEMP_DIR = path.resolve(__dirname, '../temp');
1212
const TEMPLATE_DIR = path.resolve(__dirname);
13-
const FILES_TO_IGNORE = ['index.js', 'content/pipelines v2/_index.md', 'content/pipelines v2/spec.md'];
13+
const FILES_TO_IGNORE = ['index.js'];
1414
const baseDir = path.resolve(TEMP_DIR, './content');
1515
const ALLOW_BETA_COMMANDS = process.env.ALLOW_BETA_COMMANDS;
1616
const categoriesOrder = {
1717
authentication: 30,
1818
pipelines : 40,
19+
'pipelines v2 (beta)' : 42,
1920
builds: 50,
2021
'operate on resources' : 60,
2122
contexts : 70 ,
@@ -340,7 +341,7 @@ const createDownloadPage = async () => {
340341
const RequestOptions = {
341342
url: 'https://api.github.com/repos/codefresh-io/cli/releases/latest',
342343
headers: {
343-
'User-Agent': 'codefresh-cli}',
344+
'User-Agent': 'codefresh-cli-build',
344345
},
345346
json: true,
346347
};

lib/interface/cli/commands/context/replace.cmd.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

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

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ const _ = require('lodash');
44
const CFError = require('cf-errors');
55
const { prepareKeyValueFromCLIEnvOption, crudFilenameOption } = require('../../helpers/general');
66
const ObjectID = require('mongodb').ObjectID;
7-
const { workflow, pipeline, pipeline2, log } = require('../../../../logic').api;
8-
const authManager = require('../../../../logic').auth.manager;
9-
7+
const { workflow, pipeline, log } = require('../../../../logic').api;
108

119
const run = new Command({
1210
root: true,
@@ -79,34 +77,20 @@ const run = new Command({
7977
const variablesFromFile = argv['var-file'];
8078
const contexts = argv['context'];
8179

82-
if (!authManager.getCurrentContext()
83-
.isBetaFeatEnabled()) {
84-
// validate that passed pipeline id an a mongo object id in case of pipeline V1
85-
if (!ObjectID.isValid(pipelineId)) {
86-
throw new CFError({
87-
message: `Passed pipeline id: ${pipelineId} is not valid`,
88-
});
89-
}
80+
if (!ObjectID.isValid(pipelineId)) {
81+
throw new CFError({
82+
message: `Passed pipeline id: ${pipelineId} is not valid`,
83+
});
9084
}
9185

92-
let pipelineVersion = 'v1';
93-
if (authManager.getCurrentContext()
94-
.isBetaFeatEnabled()) {
95-
try {
96-
await pipeline.getPipelineById(pipelineId);
97-
} catch (err) {
98-
try {
99-
await pipeline2.getPipelineByName(pipelineId);
100-
pipelineVersion = 'v2';
101-
} catch (err) {
102-
throw new CFError({
103-
message: `Passed pipeline id: ${pipelineId} does not exist`,
104-
});
105-
}
106-
}
86+
try {
87+
await pipeline.getPipelineById(pipelineId);
88+
} catch (err) {
89+
throw new CFError({
90+
message: `Passed pipeline id: ${pipelineId} does not exist`,
91+
});
10792
}
10893

109-
11094
const executionRequests = [];
11195
const executionRequestTemplate = {
11296
pipelineId,
@@ -133,12 +117,7 @@ const run = new Command({
133117
}
134118

135119
_.forEach(executionRequests, async ({ pipelineId, options }) => {
136-
let workflowId;
137-
if (pipelineVersion === 'v1') {
138-
workflowId = await pipeline.runPipelineById(pipelineId, options);
139-
} else {
140-
workflowId = await pipeline2.runPipelineByName(pipelineId, options);
141-
}
120+
const workflowId = await pipeline.runPipelineById(pipelineId, options);
142121

143122
if (executionRequests.length === 1) {
144123
if (argv.detach) {

lib/interface/cli/commands/pipeline2/create.cmd.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib/interface/cli/commands/pipeline2/delete.cmd.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ const debug = require('debug')('codefresh:cli:create:pipelines2');
22
const Command = require('../../Command');
33
const CFError = require('cf-errors');
44
const _ = require('lodash');
5-
const { pipeline2 } = require('../../../../logic').api;
6-
const { specifyOutputForSingle, specifyOutputForArray } = require('../../helpers/get');
5+
const { pipeline2: pipeline } = require('../../../../logic').api;
76
const deleteRoot = require('../root/delete.cmd');
87

98

109
const command = new Command({
11-
betaCommand: true,
12-
command: 'pipeline2 [name]',
13-
aliases: ['pip2'],
10+
command: 'pipeline-v2 [name]',
11+
aliases: ['pip-v2'],
1412
parent: deleteRoot,
1513
description: 'Delete a pipeline',
1614
webDocs: {
17-
category: 'Pipelines V2',
15+
category: 'Pipelines V2 (beta)',
1816
title: 'Delete Pipeline',
1917
},
2018
builder: (yargs) => {
@@ -26,7 +24,7 @@ const command = new Command({
2624
handler: async (argv) => {
2725
const {name} = argv;
2826

29-
await pipeline2.deletePipelineByName(name);
27+
await pipeline.deletePipelineByName(name);
3028
console.log(`Pipeline '${name}' deleted.`);
3129
},
3230
});

lib/interface/cli/commands/pipeline2/get.cmd.js

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,76 @@ const debug = require('debug')('codefresh:cli:create:pipelines2');
22
const Command = require('../../Command');
33
const CFError = require('cf-errors');
44
const _ = require('lodash');
5-
const { pipeline2 } = require('../../../../logic').api;
6-
const { specifyOutputForSingle, specifyOutputForArray } = require('../../helpers/get');
5+
const DEFAULTS = require('../../defaults');
6+
const { pipeline2: pipeline } = require('../../../../logic').api;
7+
const { prepareKeyValueFromCLIEnvOption, printError } = require('../../helpers/general');
8+
const { specifyOutputForArray } = require('../../helpers/get');
9+
710
const getRoot = require('../root/get.cmd');
811

912

1013
const command = new Command({
11-
betaCommand: true,
12-
command: 'pipelines2 [name..]',
13-
aliases: ['pip2', 'pipeline2'],
14+
command: 'pipelines-v2 [name..]',
15+
aliases: ['pip-v2', 'pipeline-v2'],
1416
parent: getRoot,
1517
description: 'Get a specific pipeline or an array of pipelines',
1618
webDocs: {
17-
category: 'Pipelines V2',
18-
title: 'Get Pipeline V2',
19+
category: 'Pipelines V2 (beta)',
20+
title: 'Get Pipeline',
1921
},
2022
builder: (yargs) => {
2123
return yargs
2224
.positional('name', {
2325
describe: 'Pipeline name',
26+
})
27+
.option('name-regex', {
28+
describe: 'Filter pipelines by name',
29+
})
30+
.option('label', {
31+
describe: 'Filter by a label',
32+
alias: 'l',
33+
default: [],
34+
})
35+
.option('limit', {
36+
describe: 'Limit amount of returned results',
37+
default: DEFAULTS.GET_LIMIT_RESULTS,
38+
})
39+
.option('page', {
40+
describe: 'Paginated page',
41+
default: DEFAULTS.GET_PAGINATED_PAGE,
2442
});
2543
},
2644
handler: async (argv) => {
27-
const {names, output} = argv;
28-
let pipelines = [];
45+
const {name: names, output} = argv;
46+
const limit = argv.limit;
47+
const offset = (argv.page - 1) * limit;
48+
const nameRegex = argv['name-regex'];
49+
const labels = prepareKeyValueFromCLIEnvOption(argv.label);
50+
51+
52+
const pipelines = [];
2953
if (!_.isEmpty(names)) {
3054
for (const name of names) {
31-
const currPipeline = await pipeline2.getPipelineByName(name);
32-
pipelines.push(currPipeline);
55+
try {
56+
const currPipeline = await pipeline.getPipelineByName(name);
57+
pipelines.push(currPipeline);
58+
} catch (err) {
59+
const message = err.toString()
60+
.includes('404') ? `Pipeline '${name}' was not found.` : 'Error occurred';
61+
throw new CFError({
62+
cause: err,
63+
message,
64+
});
65+
}
3366
}
3467
} else {
35-
pipelines = await pipeline2.getAll();
68+
specifyOutputForArray(output, await pipeline.getAll({
69+
limit,
70+
offset,
71+
nameRegex,
72+
labels,
73+
}));
3674
}
37-
specifyOutputForArray(output, pipelines);
3875
},
3976
});
4077

0 commit comments

Comments
 (0)