Set a dated file name using environment variables

How to set a dated file name using workspaces and environment variables

You can use workspaces and environment variables to include a date in the filename. You can find an example `config.yml` file here: 

 

# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference

version: 2.1

jobs:
say-date:
  docker:
  - image: cimg/base:stable
parameters:
date:
    type: string
    default: none
  steps:
    - checkout
    - run:
name: set var
command: echo "export DATETIME=`date +%Y%m%d.%H%M`" >> $BASH_ENV
  - run: echo "$DATETIME"
    - run: mkdir -p workspace
    - run: echo "export DATETIME=datetime.`date +%Y%m%d.%H%M%S`" >>workspace/new-env-vars
  - run: echo "export BOB=$BAZ" >> workspace/new-env-vars
  - run: cat workspace/new-env-vars
  - run: cat workspace/new-env-vars >> $BASH_ENV
  - run: echo ${DATETIME:-NULL}
  - run:
      name: make test artifacts
command: |
mkdir /tmp/artifacts;
echo "my artifact files in a dir" > /tmp/artifacts/encap-staging-no-color_${DATETIME:-NULL}.txt
- store_artifacts:
path: /tmp/artifacts
- persist_to_workspace:
root: workspace
paths:
- new-env-vars

workflows:
  say-date-workflow:
    jobs:
      - say-date
Was this article helpful?
0 out of 1 found this helpful

Comments

0 comments

Article is closed for comments.