Environment variables don't expand inside the `cache_directories` directive

envars
caching
cache

#1

Hello. I wanted to install the latest (at the moment) version of ElasticSearch, so I set up circle.ci as described in this guide — and it worked great. Then I decided to “DRY-out” repeated ElasticSearch version so it can be easily changed later. I modified my config to use the version defined via an environment variable:

machine:
  environment:
    ELASTIC_VERSION: 5.1.2

dependencies:
  cache_directories:
    - elasticsearch-${ELASTIC_VERSION}
  post:
    - if [[ ! -e elasticsearch-${ELASTIC_VERSION} ]]; then wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTIC_VERSION}.tar.gz && tar -xzf elasticsearch-${ELASTIC_VERSION}.tar.gz; fi
    - elasticsearch-${ELASTIC_VERSION}/bin/elasticsearch:
        background: true

I pushed this change to the repo and waited until the build finished successfully, then rebuilt it twice, each time ElasticSearch was downloaded. Also, there was a warning:

circle.yml specified cache directory: /home/ubuntu/REPONAME/elasticsearch-${ELASTIC_VERSION} but it does not exist

So I’ve figured out that environment variables just don’t expand inside the cache_directories directive. I don’t know if it’s made by intention or just have not been implemented yet, but I think that it would be a nice feature to have, so I have decided to report this.

Thanks.


#2

We have also noticed this issue, seems weird that we can’t use variables in cache_directories.


#3

Could you try this on 2.0?


#4

Hello, @zzak. I have just requested 2.0 beta access and will try it as soon as I receive confirmation.

I have briefly read about the 2.0 features, and it seems like with 2.0 it is better to use the dedicated Docker image to get a specific version of ElasticSearch, so my original use-case does not longer apply. Can you clarify this?


#5

You can run builds- it’s an open beta. Just update your configuration to the 2.0 syntax and your build will run on the new platform.

Yes, you can specify the latest tag on 2.0, solving your original issue.


#6

Thanks, will try it as soon as I have free time!


#7

I am having the same problem with cache_directories on 1.0

I would try 2.0 but I am still trying to learn 1.0 and it would be too take too much time to switch to 2.0 just to solve this one problem.

(Though I do plan to switch to 2.0 once I get a full setup working on 1.0.)


#8