Skip to content

Commit 4819e39

Browse files
committed
Transform date in unix timestamp
Signed-off-by: Federico Busetti <[email protected]>
1 parent f9a6fee commit 4819e39

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

.gitlab_ci/_templates.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,18 @@ variables:
5252
services:
5353
- docker:$DOCKER_VERSION-dind
5454
script:
55-
# - export UNIX_TIMESTAMP=$(date -d "$CI_COMMIT_TIMESTAMP" -D "%Y-%m-%dT%H:%M:%SZ"+%s)
56-
# - echo "Unix timestamp - $UNIX_TIMESTAMP"
57-
- echo "Tagging $DOCKER_IMAGE_NAME:$PROMOTED_ENVIRONMENT-$CI_COMMIT_TIMESTAMP from $DOCKER_IMAGE_FULL_TAG"
55+
# Remove the UTC offset, not supported by `date` in docker image (busybox)
56+
- export CLEAN_DATETIME=$(echo "$CI_COMMIT_TIMESTAMP" | sed 's/+00:00//' | sed 's/Z//')
57+
# Transform in unix timestamp
58+
- export UNIX_TIMESTAMP=$(date -d "$CLEAN_DATETIME" -D "%Y-%m-%dT%H:%M:%SZ"+%s)
59+
- echo "Unix timestamp - $UNIX_TIMESTAMP"
60+
- echo "Tagging $DOCKER_IMAGE_NAME:$PROMOTED_ENVIRONMENT-$UNIX_TIMESTAMP from $DOCKER_IMAGE_FULL_TAG"
5861
- docker buildx imagetools create
5962
--annotation "index:org.opencontainers.image.version=$CI_COMMIT_SHORT_SHA"
6063
--annotation "index:org.opencontainers.image.revision=$CI_COMMIT_SHA"
6164
--annotation "index:org.opencontainers.image.source=$CI_PROJECT_URL"
6265
--annotation "index:org.opencontainers.image.created=$CI_JOB_STARTED_AT"
63-
--tag "$DOCKER_IMAGE_NAME:$PROMOTED_ENVIRONMENT-$CI_COMMIT_TIMESTAMP"
66+
--tag "$DOCKER_IMAGE_NAME:$PROMOTED_ENVIRONMENT-$UNIX_TIMESTAMP"
6467
"$DOCKER_IMAGE_FULL_TAG"
6568

6669
.python-typing:

0 commit comments

Comments
 (0)