1
votes

So, I'm running GitLab CI on Enterprise Edition to build my project and then deploy on success.

I have two problems: 1. I cannot git push my branch to a secure SSH remote. 2. How do I force it to only deploy on a successful build?

Here is my current configuration:

stages:
  - build
  - deploy

services:
  - mysql:latest

variables:
  MYSQL_DATABASE: el_duderino
  MYSQL_ROOT_PASSWORD: mysql_strong_password

node:
  image: monostream/nodejs-gulp-bower
  stage: build
  script:
    - npm install
    - bower install --allow-root
    - gulp

migrations:
  image: eboraas/laravel
  stage: build
  script:
    - composer install
    - cp .env.testing .env
    - php artisan key:generate
    - php artisan migrate --force
    - echo "Done!"

deploy_test:
  stage: deploy
  script:
    - echo "Deploy to test server."
    - git remote set-url test ssh://[email protected]/var/repo/subPortalTest.git
    - git push test master
  environment:
    name: Test
    url: http://10.16.0.148/
  only:
    - master

My deploy_test job fails and returns the following:

Host key verification failed.

fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

1
Gitlab has an example on adding ssh-agent enabled SSH keys to your pipelines. You need the deploy target server's private SSH key in your CI config in Gitlab as a private variable.ojrask

1 Answers

1
votes
  1. How do I force it to only deploy on a successful build
    Answer: you can use dependency and on_success yaml command, when build verify job is successful then deploy job will execute based on it's dependency.
    And use on_success command so when previous job will execute successfully then will start this job.

Like

JobDeployToProd:
    stage: Deploy
    script: your commands
    tags:
     - Deploy
    allow_failure: false
    when : on_success
    dependency: JobBuildVerify