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
56 changes: 56 additions & 0 deletions source/tasks/Deploy/DeployV6/inputCommandBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,60 @@ describe("getInputCommand", () => {
const command = createCommandFromInputs(logger, task);
expect(command.EnvironmentNames).toStrictEqual(["dev", "test", "prod"]);
});

test("DeployAt populates RunAt", () => {
task.addVariableString("Space", "Default");
task.addVariableString("Environments", "test");
task.addVariableString("Project", "project 1");
task.addVariableString("ReleaseNumber", "1.2.3");
task.addVariableString("DeployAt", "2026-04-02T09:00:00+10:00");

const command = createCommandFromInputs(logger, task);
expect(command.RunAt).toStrictEqual(new Date("2026-04-02T09:00:00+10:00"));
expect(command.NoRunAfter).toBeUndefined();
});

test("DeployAtExpiry populates NoRunAfter", () => {
task.addVariableString("Space", "Default");
task.addVariableString("Environments", "test");
task.addVariableString("Project", "project 1");
task.addVariableString("ReleaseNumber", "1.2.3");
task.addVariableString("DeployAt", "2026-04-02T09:00:00+10:00");
task.addVariableString("DeployAtExpiry", "2026-04-02T17:00:00+10:00");

const command = createCommandFromInputs(logger, task);
expect(command.RunAt).toStrictEqual(new Date("2026-04-02T09:00:00+10:00"));
expect(command.NoRunAfter).toStrictEqual(new Date("2026-04-02T17:00:00+10:00"));
});

test("DeployAt and DeployAtExpiry absent when inputs not provided", () => {
task.addVariableString("Space", "Default");
task.addVariableString("Environments", "test");
task.addVariableString("Project", "project 1");
task.addVariableString("ReleaseNumber", "1.2.3");

const command = createCommandFromInputs(logger, task);
expect(command.RunAt).toBeUndefined();
expect(command.NoRunAfter).toBeUndefined();
});

test("invalid DeployAt throws error", () => {
task.addVariableString("Space", "Default");
task.addVariableString("Environments", "test");
task.addVariableString("Project", "project 1");
task.addVariableString("ReleaseNumber", "1.2.3");
task.addVariableString("DeployAt", "notadate");

expect(() => createCommandFromInputs(logger, task)).toThrowError("DeployAt 'notadate' is not a valid ISO 8601 date-time string.");
});

test("invalid DeployAtExpiry throws error", () => {
task.addVariableString("Space", "Default");
task.addVariableString("Environments", "test");
task.addVariableString("Project", "project 1");
task.addVariableString("ReleaseNumber", "1.2.3");
task.addVariableString("DeployAtExpiry", "notadate");

expect(() => createCommandFromInputs(logger, task)).toThrowError("DeployAtExpiry 'notadate' is not a valid ISO 8601 date-time string.");
});
});
11 changes: 11 additions & 0 deletions source/tasks/Deploy/DeployV6/inputCommandBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,30 @@ export function createCommandFromInputs(logger: Logger, task: TaskWrapper): Crea
}
logger.debug?.("Environments:" + environmentsField);

const deployAt = task.getInput("DeployAt");
const deployAtExpiry = task.getInput("DeployAtExpiry");

const command: CreateDeploymentUntenantedCommandV1 = {
spaceName: task.getInput("Space", true) || "",
ProjectName: task.getInput("Project", true) || "",
ReleaseVersion: task.getInput("ReleaseNumber", true) || "",
EnvironmentNames: environments,
UseGuidedFailure: task.getBoolean("UseGuidedFailure") || undefined,
Variables: variablesMap || undefined,
RunAt: deployAt ? new Date(deployAt) : undefined,
NoRunAfter: deployAtExpiry ? new Date(deployAtExpiry) : undefined,
};

const errors: string[] = [];
if (command.spaceName === "") {
errors.push("The Octopus space name is required.");
}
if (deployAt && isNaN(new Date(deployAt).getTime())) {
errors.push(`DeployAt '${deployAt}' is not a valid ISO 8601 date-time string.`);
}
if (deployAtExpiry && isNaN(new Date(deployAtExpiry).getTime())) {
errors.push(`DeployAtExpiry '${deployAtExpiry}' is not a valid ISO 8601 date-time string.`);
}

if (errors.length > 0) {
throw new Error("Failed to successfully build parameters.\n" + errors.join("\n"));
Expand Down
18 changes: 18 additions & 0 deletions source/tasks/Deploy/DeployV6/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@
"required": false,
"helpMarkDown": "Whether to use guided failure mode if errors occur during the deployment."
},
{
"name": "DeployAt",
"type": "string",
"label": "Scheduled deployment time",
"defaultValue": "",
"required": false,
"helpMarkDown": "Schedule the deployment to run at a specific time. Accepts an ISO 8601 date-time string.",
"groupName": "advanced"
},
{
"name": "DeployAtExpiry",
"type": "string",
"label": "Deployment expiry time",
"defaultValue": "",
"required": false,
"helpMarkDown": "Cancel the deployment if it has not started by this time. Accepts an ISO 8601 date-time string.",
"groupName": "advanced"
},
{
"name": "AdditionalArguments",
"type": "string",
Expand Down
56 changes: 56 additions & 0 deletions source/tasks/Deploy/DeployV7/inputCommandBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,60 @@ describe("getInputCommand", () => {
const command = createCommandFromInputs(logger, task);
expect(command.EnvironmentNames).toStrictEqual(["dev", "test", "prod"]);
});

test("DeployAt populates RunAt", () => {
task.addVariableString("Space", "Default");
task.addVariableString("Environments", "test");
task.addVariableString("Project", "project 1");
task.addVariableString("ReleaseNumber", "1.2.3");
task.addVariableString("DeployAt", "2026-04-02T09:00:00+10:00");

const command = createCommandFromInputs(logger, task);
expect(command.RunAt).toStrictEqual(new Date("2026-04-02T09:00:00+10:00"));
expect(command.NoRunAfter).toBeUndefined();
});

test("DeployAtExpiry populates NoRunAfter", () => {
task.addVariableString("Space", "Default");
task.addVariableString("Environments", "test");
task.addVariableString("Project", "project 1");
task.addVariableString("ReleaseNumber", "1.2.3");
task.addVariableString("DeployAt", "2026-04-02T09:00:00+10:00");
task.addVariableString("DeployAtExpiry", "2026-04-02T17:00:00+10:00");

const command = createCommandFromInputs(logger, task);
expect(command.RunAt).toStrictEqual(new Date("2026-04-02T09:00:00+10:00"));
expect(command.NoRunAfter).toStrictEqual(new Date("2026-04-02T17:00:00+10:00"));
});

test("DeployAt and DeployAtExpiry absent when inputs not provided", () => {
task.addVariableString("Space", "Default");
task.addVariableString("Environments", "test");
task.addVariableString("Project", "project 1");
task.addVariableString("ReleaseNumber", "1.2.3");

const command = createCommandFromInputs(logger, task);
expect(command.RunAt).toBeUndefined();
expect(command.NoRunAfter).toBeUndefined();
});

test("invalid DeployAt throws error", () => {
task.addVariableString("Space", "Default");
task.addVariableString("Environments", "test");
task.addVariableString("Project", "project 1");
task.addVariableString("ReleaseNumber", "1.2.3");
task.addVariableString("DeployAt", "notadate");

expect(() => createCommandFromInputs(logger, task)).toThrowError("DeployAt 'notadate' is not a valid ISO 8601 date-time string.");
});

test("invalid DeployAtExpiry throws error", () => {
task.addVariableString("Space", "Default");
task.addVariableString("Environments", "test");
task.addVariableString("Project", "project 1");
task.addVariableString("ReleaseNumber", "1.2.3");
task.addVariableString("DeployAtExpiry", "notadate");

expect(() => createCommandFromInputs(logger, task)).toThrowError("DeployAtExpiry 'notadate' is not a valid ISO 8601 date-time string.");
});
});
11 changes: 11 additions & 0 deletions source/tasks/Deploy/DeployV7/inputCommandBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,30 @@ export function createCommandFromInputs(logger: Logger, task: TaskWrapper): Crea
}
logger.debug?.("Environments:" + environmentsField);

const deployAt = task.getInput("DeployAt");
const deployAtExpiry = task.getInput("DeployAtExpiry");

const command: CreateDeploymentUntenantedCommandV1 = {
spaceName: task.getInput("Space", true) || "",
ProjectName: task.getInput("Project", true) || "",
ReleaseVersion: task.getInput("ReleaseNumber", true) || "",
EnvironmentNames: environments,
UseGuidedFailure: task.getBoolean("UseGuidedFailure") || undefined,
Variables: variablesMap || undefined,
RunAt: deployAt ? new Date(deployAt) : undefined,
NoRunAfter: deployAtExpiry ? new Date(deployAtExpiry) : undefined,
};

const errors: string[] = [];
if (command.spaceName === "") {
errors.push("The Octopus space name is required.");
}
if (deployAt && isNaN(new Date(deployAt).getTime())) {
errors.push(`DeployAt '${deployAt}' is not a valid ISO 8601 date-time string.`);
}
if (deployAtExpiry && isNaN(new Date(deployAtExpiry).getTime())) {
errors.push(`DeployAtExpiry '${deployAtExpiry}' is not a valid ISO 8601 date-time string.`);
}

if (errors.length > 0) {
throw new Error("Failed to successfully build parameters.\n" + errors.join("\n"));
Expand Down
18 changes: 18 additions & 0 deletions source/tasks/Deploy/DeployV7/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@
"required": false,
"helpMarkDown": "Whether to use guided failure mode if errors occur during the deployment."
},
{
"name": "DeployAt",
"type": "string",
"label": "Scheduled deployment time",
"defaultValue": "",
"required": false,
"helpMarkDown": "Schedule the deployment to run at a specific time. Accepts an ISO 8601 date-time string.",
"groupName": "advanced"
},
{
"name": "DeployAtExpiry",
"type": "string",
"label": "Deployment expiry time",
"defaultValue": "",
"required": false,
"helpMarkDown": "Cancel the deployment if it has not started by this time. Accepts an ISO 8601 date-time string.",
"groupName": "advanced"
},
{
"name": "AdditionalArguments",
"type": "string",
Expand Down
Loading