Hi, this:
machine:
environment:
START_TIME: "`date +%Y-%m-%d-%T`"
PATH: "${HOME}/bin:${PATH}"
DO_DEFAULT_REGION: "nyc3"
AWS_DEFAULT_REGION: "us-east-1"
TEST_NAME: "TEST-`tr -dc '[:xdigit:]' < /dev/urandom | head -c 8`"
IMAGE_NAME: "$TEST_NAME-$START_TIME"
Clearly won’t have the expected result because the date
and tr
command will vary per line in the circleci file. How do I get this data to be generated once per run? Thanks.
Answered my own question:
machine:
environment:
PATH: "${HOME}/bin:${PATH}"
DO_DEFAULT_REGION: "nyc3"
AWS_DEFAULT_REGION: "us-east-1"
python:
version: 2.7.10
dependencies:
cache_directories:
- "~/bin"
pre:
- ./env_hack.sh
Here is env_hack.sh:
#!/bin/bash
#varibles hack.
export START_TIME="`date +%Y-%m-%d-%T`"
export TEST_NAME="TEST-`tr -dc '[:xdigit:]' < /dev/urandom | head -c 8`"
export IMAGE_NAME="$TEST_NAME-$START_TIME"
echo -e "export START_TIME=$START_TIME\nexport TEST_NAME=$TEST_NAME\nexport IMAGE_NAME=$IMAGE_NAME\n" >> ~/.circlerc
It would be nice if this technique was mentioned in the documentation, the persistence of variables is done in an obtuse way.