diff --git a/.gitignore b/.gitignore index 023323e..222e31e 100644 --- a/.gitignore +++ b/.gitignore @@ -200,3 +200,4 @@ _Pvt_Extensions /.cr /*/v[0-9]/*.js /*/v[0-9]/*.js.map +./*/v[0-9]/*.tsbuildinfo diff --git a/vsts-variable-set/v1/tsconfig.tsbuildinfo b/vsts-variable-set/v1/tsconfig.tsbuildinfo new file mode 100644 index 0000000..2c4e307 --- /dev/null +++ b/vsts-variable-set/v1/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"root":["./vsts-variable-set.ts"],"version":"5.8.3"} \ No newline at end of file diff --git a/vsts-variable-set/v2/tsconfig.tsbuildinfo b/vsts-variable-set/v2/tsconfig.tsbuildinfo new file mode 100644 index 0000000..2c4e307 --- /dev/null +++ b/vsts-variable-set/v2/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"root":["./vsts-variable-set.ts"],"version":"5.8.3"} \ No newline at end of file diff --git a/vsts-variable-set/v3/task.json b/vsts-variable-set/v3/task.json index a99f5bb..059436c 100644 --- a/vsts-variable-set/v3/task.json +++ b/vsts-variable-set/v3/task.json @@ -59,7 +59,8 @@ "type": "pickList", "options": { "value": "value", - "env": "env" + "env": "env", + "datetime": "current date/time" } }, { @@ -82,6 +83,15 @@ "aliases": ["Env", "Environment"], "visibleRule": "From=env" }, + { + "defaultValue": "yyyy-MM-dd HH:mm:ss", + "helpMarkdown": "Format string for the current date and time. Supported patterns: yyyy (4-digit year), yy (2-digit year), MM (2-digit month), dd (2-digit day), HH (24-hour), hh (12-hour), mm (minute), ss (second), tt (AM/PM). Example: 'yyyy-MM-dd HH:mm:ss' produces '2023-12-25 14:30:00'.", + "label": "Date/Time Format", + "name": "DateTimeFormat", + "required": true, + "type": "string", + "visibleRule": "From=datetime" + }, { "defaultValue": false, "helpMarkdown": "Save variable as a secret.", diff --git a/vsts-variable-set/v3/tsconfig.tsbuildinfo b/vsts-variable-set/v3/tsconfig.tsbuildinfo new file mode 100644 index 0000000..2c4e307 --- /dev/null +++ b/vsts-variable-set/v3/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"root":["./vsts-variable-set.ts"],"version":"5.8.3"} \ No newline at end of file diff --git a/vsts-variable-set/v3/vsts-variable-set.ts b/vsts-variable-set/v3/vsts-variable-set.ts index 85b4a15..142fa3c 100644 --- a/vsts-variable-set/v3/vsts-variable-set.ts +++ b/vsts-variable-set/v3/vsts-variable-set.ts @@ -2,6 +2,47 @@ const variable = tl.getInput("VariableName", true); +function formatDateTime(format: string): string { + const now = new Date(); + + // Simple and robust approach - only support explicit multi-character patterns + // This avoids conflicts with single characters in normal text + let formatted = format; + + // Year patterns + formatted = formatted.replace(/yyyy/g, now.getFullYear().toString()); + formatted = formatted.replace(/yy/g, now.getFullYear().toString().slice(-2)); + + // Month patterns (2-digit and single digit with leading zero requirement) + const month = (now.getMonth() + 1).toString().padStart(2, '0'); + formatted = formatted.replace(/MM/g, month); + + // Day patterns + const day = now.getDate().toString().padStart(2, '0'); + formatted = formatted.replace(/dd/g, day); + + // Hour 24-hour patterns + const hour = now.getHours().toString().padStart(2, '0'); + formatted = formatted.replace(/HH/g, hour); + + // Hour 12-hour patterns + const hour12 = (now.getHours() % 12 || 12).toString().padStart(2, '0'); + formatted = formatted.replace(/hh/g, hour12); + + // Minute patterns + const minute = now.getMinutes().toString().padStart(2, '0'); + formatted = formatted.replace(/mm/g, minute); + + // Second patterns + const second = now.getSeconds().toString().padStart(2, '0'); + formatted = formatted.replace(/ss/g, second); + + // AM/PM patterns + formatted = formatted.replace(/tt/g, now.getHours() >= 12 ? 'PM' : 'AM'); + + return formatted; +} + function getValue() { const from = tl.getInput("From") || "value"; @@ -15,6 +56,11 @@ function getValue() { return process.env[tl.getInput("Env", true)]; } + case "datetime": + { + const format = tl.getInput("DateTimeFormat", true) || "yyyy-MM-dd HH:mm:ss"; + return formatDateTime(format); + } default: { return ""; diff --git a/vsts-variable-transform/v1/tsconfig.tsbuildinfo b/vsts-variable-transform/v1/tsconfig.tsbuildinfo new file mode 100644 index 0000000..37049a9 --- /dev/null +++ b/vsts-variable-transform/v1/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"root":["./vsts-variable-transform.ts"],"version":"5.8.3"} \ No newline at end of file diff --git a/vsts-variable-transform/v2/tsconfig.tsbuildinfo b/vsts-variable-transform/v2/tsconfig.tsbuildinfo new file mode 100644 index 0000000..37049a9 --- /dev/null +++ b/vsts-variable-transform/v2/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"root":["./vsts-variable-transform.ts"],"version":"5.8.3"} \ No newline at end of file diff --git a/vsts-variable-transform/v3/tsconfig.tsbuildinfo b/vsts-variable-transform/v3/tsconfig.tsbuildinfo new file mode 100644 index 0000000..37049a9 --- /dev/null +++ b/vsts-variable-transform/v3/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"root":["./vsts-variable-transform.ts"],"version":"5.8.3"} \ No newline at end of file