Skip to content

Commit 750a055

Browse files
committed
Implemented when:manual tag
1 parent ffbd58c commit 750a055

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ Artifacts works right now, as along as you don't overwirte git tracked files and
8787
- Verbosity on .gitlab-ci.local.yml overrides and appends.
8888

8989
## Unsupported tags, will be implemented in order
90-
- when:manual
9190
- rules
9291
- when:on_failure
9392
- when:delayed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "tslint --project .",
1212
"lint-fix": "tslint --fix --project .",
1313
"ncu": "ncu --semverLevel major -e 2",
14-
"test-yml-spec": "node -r source-map-support/register dist/index.js --cwd tests/test-yml-spec"
14+
"test-yml-spec": "node -r source-map-support/register dist/index.js manual_job_invoked_from_cli --cwd tests/test-yml-spec"
1515
},
1616
"bin": "dist/index.js",
1717
"dependencies": {

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ const runJobs = async () => {
5252
const jobNames = `${jobs.map((j) => j.name).join(" ")}`;
5353
console.log(`=> ${c.yellow(`${stageName}`)} > ${c.blueBright(`${jobNames}`)} ${c.magentaBright("starting")}...`);
5454
for (const job of jobs) {
55+
if (job.isManual() && !argv._.includes(job.name)) {
56+
console.log(`${c.blueBright(`${job.name}`)} skipped. Manual job`);
57+
continue;
58+
}
5559
const jobPromise = job.start();
5660
promises.push(jobPromise);
5761
}

src/job.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class Job {
2222
private readonly scripts: string[] = [];
2323

2424
private readonly variables: { [key: string]: string };
25+
private readonly when: string;
2526

2627
public constructor(jobData: any, name: string, cwd: any, globals: any) {
2728
this.name = name;
@@ -49,12 +50,17 @@ export class Job {
4950
this.scripts = [].concat(jobData.script || []);
5051

5152
const ciDefault = globals.default || {};
53+
this.when = jobData.when || "on_success";
5254
this.beforeScripts = [].concat(jobData.before_script || ciDefault.before_script || globals.before_script || []);
5355
this.afterScripts = [].concat(jobData.after_script || ciDefault.after_script || globals.after_script || []);
5456
this.allowFailure = jobData.allow_failure || false;
5557
this.variables = jobData.variables || {};
5658
}
5759

60+
public isManual(): boolean {
61+
return this.when === "manual";
62+
}
63+
5864
public async start(): Promise<void> {
5965
this.running = true;
6066

@@ -131,7 +137,7 @@ export class Job {
131137
if (!l) {
132138
return;
133139
}
134-
process.stdout.write(`${c.blueBright(`${this.name}`)} ${c.greenBright(">")} ${c.green(`${l}`)}\n`);
140+
process.stdout.write(`${c.blueBright(`${this.name}`)} ${c.greenBright(">")} ${l}\n`);
135141
});
136142
});
137143
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,16 @@ after_script_test:
6464
- echo "Trying make an error, but my exit code is ignored, cause i'm an after_script"
6565
- exit 127
6666

67+
manual_job:
68+
<<: *tags
69+
when: manual
70+
stage: last
71+
script:
72+
- echo "I'm not going to be called"
73+
74+
manual_job_invoked_from_cli:
75+
<<: *tags
76+
when: manual
77+
stage: last
78+
script:
79+
- echo "I was invoked manually, because 'gitlab-local-pipeline manual_job_invoked_from_cli' was called"

0 commit comments

Comments
 (0)