Running Redis on Travis CI

2019-05-23 04:13发布

问题:

I just included a Redis Store in my Express application and got it to work.

I wanted to include this Redis Store in Travis CI for my code to keep working there. I read in the Travis Documentation that it is possible to start Redis, with the factory settings.

In my project, I don't use the factory settings, I wrote my own redis.conf file which specifies the port and the password.

So I added the following line to my .travis.yml file:

services:
  - redis-server --port 6380 --requirepass 'secret'

But this returns the following on Travis CI:

$ sudo service redis-server\ --port\ 6380\ --requirepass\ \'secret\' start
  redis-server --port 6380 --requirepass 'secret': unrecognized service

Is there any way to fix this?

回答1:

If you want to customize the option for Redis on Travis CI, I'd suggest not using the services section, but rather do this:

before_script: sudo redis-server /etc/redis/redis.conf --port 6380 --requirepass 'secret'

The services section runs services using their init/upstart scripts, which may not support the options you've added in there. The command is also escaped for security reasons, hence the documentation only hinting that you can list normal service names in that section.