Skip to content

Commit 2136e3e

Browse files
committed
Added support "extend" tag feature
1 parent 6237bbe commit 2136e3e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/job.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as c from "ansi-colors";
2+
import * as deepExtend from "deep-extend";
23
import * as prettyHrtime from "pretty-hrtime";
34
import * as shelljs from "shelljs";
45

@@ -27,6 +28,23 @@ export class Job {
2728
this.cwd = cwd;
2829
this.globals = globals;
2930

31+
// Parse extends
32+
if (jobData.extends) {
33+
const extendList = [].concat(jobData.extends);
34+
const deepExtendList: any[] = [];
35+
extendList.forEach((parentJobName) => {
36+
if (!globals[parentJobName]) {
37+
console.error(`${c.red(`'${parentJobName}' could not be found`)}`);
38+
process.exit(1);
39+
}
40+
deepExtendList.push(globals[parentJobName]);
41+
});
42+
43+
deepExtendList.push(jobData);
44+
// tslint:disable-next-line:no-parameter-reassignment
45+
jobData = deepExtend.apply(this, deepExtendList);
46+
}
47+
3048
this.stage = jobData.stage || ".pre";
3149
this.scripts = [].concat(jobData.script || []);
3250

tests/test-yml-spec/.gitlab-ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,27 @@ include:
66
.defaultTags: &tags
77
tags: [some_runner_tag]
88

9+
.parent0:
10+
<<: *tags
11+
stage: prepare
12+
before_script: [echo "I'm from parents0 (before_script)"]
13+
script: [echo "I'm from parents0 (script)"]
14+
after_script: [echo "I'm from parents0 (after_script)"]
15+
16+
.parent1:
17+
stage: build
18+
before_script: [echo "I'm from parents1 (before_script)"]
19+
script: [echo "I'm from parents1 (script)"]
20+
after_script: [echo "I'm from parents1 (after_script)"]
21+
922
variables:
1023
PROJECT_NAME: test-yml-spec-project
1124

25+
extending:
26+
extends: [.parent0, .parent1]
27+
script:
28+
- echo "I'm from extending (script)"
29+
1230
echo_project_name:
1331
<<: *tags
1432
stage: startup

0 commit comments

Comments
 (0)