diff --git a/src/lib/Components/Job/index.ts b/src/lib/Components/Job/index.ts index 4d7cecf..55f1fbd 100644 --- a/src/lib/Components/Job/index.ts +++ b/src/lib/Components/Job/index.ts @@ -3,6 +3,7 @@ import { Command } from '../Commands/exports/Command'; import { Executable } from '../Executors/types/ExecutorParameters.types'; import { Generable } from '../index'; import { + BooleanParameter, EnvironmentParameter, IntegerParameter, StringParameter, @@ -34,6 +35,10 @@ export class Job implements Generable, Executable { * Number of parallel instances of this job to run (defaults to 1 if undefined) */ parallelism: IntegerParameter | undefined; + /** + * Whether to use CircleCI IP Ranges for the job (defaults to false if undefined) + */ + circleci_ip_ranges: BooleanParameter | undefined; // Execution environment properties @@ -62,6 +67,7 @@ export class Job implements Generable, Executable { this.shell = properties?.shell; this.working_directory = properties?.working_directory; this.parallelism = properties?.parallelism; + this.circleci_ip_ranges = properties?.circleci_ip_ranges; } /** @@ -81,6 +87,7 @@ export class Job implements Generable, Executable { shell: this.shell, working_directory: this.working_directory, parallelism: this.parallelism, + circleci_ip_ranges: this.circleci_ip_ranges, }; } /** diff --git a/src/lib/Components/Job/types/Job.types.ts b/src/lib/Components/Job/types/Job.types.ts index 3fa2026..2a72cc9 100644 --- a/src/lib/Components/Job/types/Job.types.ts +++ b/src/lib/Components/Job/types/Job.types.ts @@ -15,6 +15,7 @@ import { JobParameterLiteral } from '../../Parameters/types/CustomParameterLiter export type JobContentsShape = { steps: unknown[]; parallelism?: number; + circleci_ip_ranges?: boolean; } & AnyExecutorShape & JobEnvironmentShape; @@ -40,6 +41,7 @@ export type JobDependencies = { export type JobOptionalProperties = { parallelism?: number; + circleci_ip_ranges?: boolean; } & ExecutableProperties; export type UnknownJobShape = { diff --git a/tests/Job.test.ts b/tests/Job.test.ts index f51ca79..49f4e93 100644 --- a/tests/Job.test.ts +++ b/tests/Job.test.ts @@ -26,6 +26,35 @@ describe('Instantiate Docker Job', () => { }); }); +describe('Instantiate Docker Job with custom properties', () => { + const docker = new CircleCI.executors.DockerExecutor('cimg/node:lts'); + const helloWorld = new CircleCI.commands.Run({ + command: 'echo hello world', + }); + const jobName = 'my-job'; + const job = new CircleCI.Job(jobName, docker, [helloWorld], { + parallelism: 3, + circleci_ip_ranges: true, + }); + const jobContents = { + docker: [{ image: 'cimg/node:lts' }], + resource_class: 'medium', + parallelism: 3, + circleci_ip_ranges: true, + steps: [{ run: 'echo hello world' }], + }; + + it('Should match the expected output', () => { + expect(job.generate(true)).toEqual({ [jobName]: jobContents }); + }); + + it('Add job to config and validate', () => { + const myConfig = new CircleCI.Config(); + myConfig.addJob(job); + expect(myConfig.jobs.length).toBeGreaterThan(0); + }); +}); + describe('Instantiate Parameterized Docker Job With Custom Parameters', () => { const docker = new CircleCI.executors.DockerExecutor('cimg/node:lts'); const helloWorld = new CircleCI.commands.Run({