CI Push Branch to Remote on Deploy

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://git@10.16.0.148/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.


  • 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 
    
    链接地址: http://www.djcxy.com/p/85114.html

    上一篇: Jenkins管道在Gitlab推送上创建作业

    下一篇: CI将分支推送到远程部署