将redis与Gitlab CI一起使用

时间:2017-10-25 09:01:34

标签: redis continuous-integration gitlab gitlab-ci gitlab-ci-runner

我目前正在使用无服务器框架并使用共享运行程序设置gitlab ci。

以下是我的gitlab-ci.yml:

image: node:latest

services:
  - redis

cache:
  paths:
    - node_modules/
    - java/

stages:
  - build
  - test
  - review
  - staging
  - production

build:
  stage: build
  script:
      - npm install
  artifacts:
    paths:
      - node_modules/

install:java:
  stage: build
  script:
      - apt-get update
      - apt-get install -y default-jre default-jdk openjdk-7-jre openjdk-7-jdk
      - apt-get update
      - sls dynamodb install
  artifacts:
    paths:
      - java/

connect:
  image: redis
  script:
  - redis-cli -h redis PING

unit test:
  stage: test
  script:
    - sls dynamodb start
    - babel-node ./aws/createDB.js
    - npm run unit
  dependencies:
    - build
    - install:java

单元测试作业需要redis且无法连接。当单元测试作业开始时,抛出以下错误:

  

创建redis客户端时出错:错误:Redis连接到   127.0.0.1:6379失败 - 连接ECONNREFUSED 127.0.0.1:6379

有人可以指出当前配置文件有什么问题,谢谢!

1 个答案:

答案 0 :(得分:5)

redis服务的主机地址为redis而非127.0.0.1localhost

因此,请确保在所有脚本和配置文件中将redis服务的主机设置为redis