Gitlab ci deploys on test fail

I’ve noticed that gitlab deploys every time i push to master even if the test step failes.
Is there something wrong with my config?

image: rails:5.0.0

services:
  - mariadb:10.0.28

cache:
    paths:
    - .bundlercache/

before_script:
  - bundle install --jobs $(nproc) --path="./.bundlercache"

variables:
  MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
  OPI_DB_HOST: mariadb
  OPI_DB_USER: root
  OPI_DB_NAME_TEST: test_db

test:
  script:
  - bundle exec rubocop
  - bundle exec rake db:create
  - bundle exec rake test

deploy:
  only:
    - master
  script:
    # Install ssh-agent if not already installed, it is required by Docker.
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    # Run ssh-agent (inside the build environment)
    - eval $(ssh-agent -s)
    # Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
    - ssh-add <(echo "$SSH_PRIVATE_KEY")
    # For Docker builds disable host key checking. Be aware that by adding that
    # you are suspectible to man-in-the-middle attacks.
    # WARNING: Use this only with the Docker executor, if you use it with shell
    # you will overwrite your user's SSH config.
    - mkdir -p ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    - bundle exec cap production deploy

You need to add something like

deploy:
  stage: deploy

to your deploy job

1 Like

thx, that worked like a charm :slight_smile: