TeamCity Current Date variable in MMdd format

前端 未结 8 1396
谎友^
谎友^ 2021-01-31 04:16

In TeamCity is there an easy way to get a variable for the current date in the format MMdd (eg 0811 for 8-Aug)?

My google-fu did not turn up an existing plugins. I look

相关标签:
8条回答
  • 2021-01-31 05:00

    If you only want to have one-line bash command in a build step, just use as below.

    echo "##teamcity[setParameter name='build.timestamp' value='$(date +%%m%%d)']"
    

    (double % symbol is for TeamCity own escape rule to use % character)

    It will set a MMdd parameter value right after the execution during runtime so very useful to put at any build step. Then, you can retrieve a parameter value afterward.

    Note that you should create build.timestamp parameter firstly to TeamCity project.

    A step further, I made a simple bash script to have bash date format timestamp. This script will set timestamp to whatever bash supported datetime format and parameter name to TeamCity.

    name=""  # TeamCity parameter name
    format="%Y-%m-%dT%H:%M:%S%z"  # ISO8601 format by default
    result=""  # a TeamCity parameter value to be set
    
    for ARGUMENT in "$@"
    do
        KEY=$(echo "$ARGUMENT" | cut -f1 -d=)
        VALUE=$(echo "$ARGUMENT" | cut -f2 -d=)
    
        case "$KEY" in
                name)              name=${VALUE} ;;
                format)     format=${VALUE} ;;
                *)
        esac
    done
    
    result=$(date "+$format")
    
    echo "##teamcity[setParameter name='$name' value='$result']"
    

    Below usage will set ISO8601 format timestamp to build.timestamp parameter.

    ./teamcity_datetime.sh name=build.timestamp
    

    If you want to set only MMdd, the execution could be as below.

    ./teamcity_datetime.sh name=build.timestamp format="%%m%%d"
    
    0 讨论(0)
  • 2021-01-31 05:01

    Similar to the Date Build Number plugin mentioned in this answer, there exists a derived plugin called Formatted Date Parameter. It provides a customizable parameter build.formatted.timestamp that can be used out of the box in fields or other parameters. No need for a separate build step.

    0 讨论(0)
提交回复
热议问题