drone-ssh: Deploy steps continue even if command returns error

Is there any way to abort execution on error? for instance right now In my deployment code I run gulp through your ssh plugin, if gulp returns a compile error I want to abort, but currently that does not happen.

I am going to wrap all my build steps in a bash script with stricter error handling, but I wanted to check if there was another way first.

Here’s what my .drone.yml currently looks like

deploy:
  ssh:
    host: gwizlv-prd01
    user: crun
    port: 22
    commands:
      - setenv build `date +%s`
      - setenv appdir "/mnt/shared/sites/people"
      - mkdir $appdir/releases/$build/
      - cd $appdir/releases/$build/
      - git clone <git repo> ./
      - composer install --no-interaction
      - cp .env.production .env
      - phpunit
      - rm -rf storage
      - ln -s $appdir/storage storage
      - php artisan clear-compiled
      - php artisan optimize
      - npm install
      - gulp
      - php artisan migrate --no-interaction --force
      - find ./ -type d -exec chmod 775 {} +
      - find ./ -type f -exec chmod 664 {} +
      - cd $appdir
      - ln -n -f -s $appdir/releases/$build $appdir/release
      - ln -n -f -s $appdir/releases/$build $appdir/last_release
    when:
      branch: master

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 24 (13 by maintainers)

Most upvoted comments

@mattbucci Please add set -e

ssh:
    image: appleboy/drone-ssh
    host: gwizlv-prd01
    user: crun
    key: ${SSH_KEY}
    port: 22
    command_timeout: 600
    script:
+     - set -e
      - setenv build ${DRONE_BUILD_NUMBER}
      - setenv appdir "/mnt/shared/sites/people"
      - mkdir $appdir/releases/$build/
      - if ( `readlink "$appdir/release" | xargs basename` == ${DRONE_BUILD_NUMBER}) echo "Build Already Deployed, cannot redeploy without causing downtime"
      - if ( `readlink "$appdir/release" | xargs basename` == ${DRONE_BUILD_NUMBER}) exit 1
      - cd $appdir/releases/$build/
      - git clone -b ${DRONE_COMMIT_BRANCH} --single-branch git@gitlab.gene.com:${DRONE_REPO}.git ./
      - git reset --hard ${DRONE_COMMIT_REF}
      - composer install --no-interaction
      - cp .env.production .env
      - vendor/bin/phpunit
      - rm -rf storage
      - ln -s $appdir/storage storage
      - php artisan clear-compiled
      - php artisan optimize --force
      - php artisan route:cache
      - npm install
      - gulp
      - if ( `readlink "$appdir/release" | xargs basename` >= ${DRONE_BUILD_NUMBER} ) echo "ABORTED - BUILD RACE CONDITION MET"
      - if ( `readlink "$appdir/release" | xargs basename` >= ${DRONE_BUILD_NUMBER}) exit 1
      - echo "Build is New - Proceeding to update the live app"
      - # if QA, dump latest PRD database into QA
      - php artisan migrate --no-interaction --force
      - find ./ -type d -exec chmod 775 {} +
      - find ./ -type f -exec chmod 664 {} +
      - cd $appdir
      - ln -n -f -s $appdir/releases/$build $appdir/release
      - ln -n -f -s $appdir/releases/$build $appdir/last_release
    when:
      branch: prod