Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ export class Parser {

// Check job variables for invalid hash of key value pairs, and cast numbers to strings
Utils.forEachRealJob(gitlabData, (jobName, jobData) => {
assert(jobData.when !== "never",
chalk`This GitLab CI configuration is invalid: jobs:${jobName} when:never can only be used in a rules section or workflow:rules`
);
for (const [key, _value] of Object.entries(jobData.variables || {})) {
let value = _value;
if (value === null) value = ""; // variable's values are nullable
Expand Down
6 changes: 6 additions & 0 deletions tests/test-cases/when/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
test-job:
stage: deploy
when: never
script:
- echo "test"
25 changes: 25 additions & 0 deletions tests/test-cases/when/integration.when.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {WriteStreamsMock} from "../../../src/write-streams";
import {handler} from "../../../src/handler";
import {initSpawnSpy} from "../../mocks/utils.mock";
import {WhenStatics} from "../../mocks/when-statics";
import {AssertionError} from "assert";
import {assert} from "console";

beforeAll(() => {
initSpawnSpy(WhenStatics.all);
});

test("when", async () => {
try {
const writeStreams = new WriteStreamsMock();
await handler({
cwd: "tests/test-cases/when",
}, writeStreams);
} catch (e: any) {
assert(e instanceof AssertionError, "e is not instanceof AssertionError");
expect(e.message).toContain("This GitLab CI configuration is invalid: jobs:test-job when:never can only be used in a rules section or workflow:rules");
return;
}

throw new Error("Error is expected but not thrown/caught");
});