Current build time

circle.yml

#1

I want to get current build time inside ci.
Like this

test:
  overrride:
    - test.sh

  post:
    - # get current build time here like `build_time_millis`

The best way I think is via environment variable like CIRCLE_CURRENT_TIME_MILLS.

Thanks,


#2

You can also try setting a timestamp at the beginning of the build. Then compare the current time at any point back to the original timestamp.


#3

I wrote bellow shell script.

#!/bin/bash
readonly api_endpoint=https://circleci.com/api/v1.1/project/github
readonly api_url="$api_endpoint/$(echo $CIRCLE_REPOSITORY_URL | cut -d "/" -f 4,5)"

readonly ci_stime=$(curl -Ls "$api_url?limit=1&circle-token=$CIRCLE_API_TOKEN" | jq -r '.[0].start_time')
readonly ci_stime_sec=$(date --date="$ci_stime" "+%s")

readonly now_sec=$(date "+%s")

echo $(($now_sec - $ci_stime_sec))

But I want to easier way.

Thanks,


#4