Skip to content

Add datetime formatting capability to variable set task #777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 15, 2025

This PR adds the ability to format the current date and time according to a user-provided format string in the vsts-variable-set task.

Changes Made

New Task Input Options

  • Added "current date/time" option to the "From" dropdown in the vsts-variable-set task (v3)
  • Added "Date/Time Format" input field with intelligent default: yyyy-MM-dd HH:mm:ss
  • The format field appears only when "From" = "datetime" for a clean UI experience

Format Pattern Support

The implementation supports common datetime format patterns:

  • yyyy - 4-digit year (2025)
  • yy - 2-digit year (25)
  • MM - 2-digit month (07)
  • dd - 2-digit day (15)
  • HH - 24-hour format (14)
  • hh - 12-hour format (02)
  • mm - 2-digit minute (30)
  • ss - 2-digit second (45)
  • tt - AM/PM indicator

Usage Examples

# Basic timestamp variable
- task: VariableSetTask@3
  inputs:
    variableName: 'BuildTimestamp'
    from: 'datetime'
    dateTimeFormat: 'yyyy-MM-dd HH:mm:ss'
  # Result: 2025-07-15 14:30:00

# Build number with datetime
- task: VariableSetTask@3
  inputs:
    variableName: 'Build.BuildNumber'
    from: 'datetime'
    dateTimeFormat: 'Build-yyyy.MM.dd.HHmm'
  # Result: Build-2025.07.15.1430

# Short date for versioning
- task: VariableSetTask@3
  inputs:
    variableName: 'VersionDate'
    from: 'datetime'
    dateTimeFormat: 'yyyyMMdd'
  # Result: 20250715

Azure Pipelines Integration

  • ✅ Works with Build.BuildNumber (updates build number)
  • ✅ Works with Release.ReleaseName (updates release name)
  • ✅ Works with custom variables (creates new pipeline variables)
  • ✅ Supports secret variables and output variables
  • ✅ Compatible with both tasklib and direct VSO commands
  • ✅ Maintains full backward compatibility

Technical Implementation

  • Minimal changes: Only modified vsts-variable-set/v3/task.json and vsts-variable-set/v3/vsts-variable-set.ts
  • Robust pattern matching: Uses ordered regex replacements to avoid conflicts with regular text
  • Clean error handling: Graceful fallbacks and sensible defaults
  • Documentation: Clear help text with examples in the task UI

This enhancement enables Azure Pipelines users to generate datetime-formatted variables for build numbers, timestamps, file naming, and custom workflow needs without requiring external tools or complex scripts.

Fixes #776.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Add the ability to format the current date and time according to a user provided format Add datetime formatting capability to variable set task Jul 15, 2025
Copilot finished work on behalf of jessehouwing July 15, 2025 12:12
@Copilot Copilot AI requested a review from jessehouwing July 15, 2025 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the ability to format the current date and time according to a user provided format
2 participants