Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Travis manually confirm next stage

Tags:

travis-ci

I have a stage test and production. I would like to manually confirm the deployment to production. Is there way to achieve this?

like image 535
isADon Avatar asked Jun 13 '18 07:06

isADon


1 Answers

You can make use of Conditional Deployments. This allows you to specify whether you push to production or test. Combine it with e.g. a check-live-deployment.sh-script and differentiate between branches and/or tagged commits.

For example:

#!/bin/bash
set -e

contains() {
    if [[ $TRAVIS_TAG = *"-live"* ]]
    then
        #"-live" is in $TRAVIS_TAG
        echo "true"
    else
        #"-live" is not in $TRAVIS_TAG
        echo "false"
    fi
}

echo "============== CHECKING IF DEPLOYMENT CONDITION IS MET =============="
export LIVE=$(contains)

and .travis.yml for a dev/staging/live-deployment to Cloud Foundry:

sudo: false
language: node_js
node_js:
  - '8.9.4'
branches:
  only:
    - master
    - "/v*/"
script:
  - printenv 
before_install:
  - chmod +x -R ci
install:
  - source ci/check_live_deployment.sh
  - ./ci/check_live_deployment.sh
deploy:
  - provider: script
    skip_cleanup: true
    script: env CF_SPACE=$CF_SPACE_DEV CF_MANIFEST=manifest-dev.yml ci/deploy_to_cf.sh
    on:
      tags: false
  - provider: script
    skip_cleanup: true
    script: env CF_SPACE=$CF_SPACE_STAGING CF_MANIFEST=manifest-staging.yml ci/deploy_to_cf.sh
    on:
      tags: true
  - provider: script
    skip_cleanup: true
    script: env CF_SPACE=$CF_SPACE_LIVE CF_MANIFEST=manifest-live.yml ci/deploy_to_cf.sh
    on:
      tags: true
      condition: $LIVE = true

This example pushes to dev if branch is master && no tag is present, staging if its a tagged commit, and staging+live if it is a tagged commit on master (a release) and the deployment-condition is met.

Granted: Maybe not the prettiest solution, but it definitely works. And this is not Travis waiting for you to manually confirm live-deployment (which would kind of ridicule the whole automated deployment principle imo), but it is a way to guarantee, that you have to manually trigger the pipeline in a specific way.

like image 84
heldic Avatar answered Oct 10 '22 05:10

heldic