Travis manually confirm next stage

后端 未结 1 1607
粉色の甜心
粉色の甜心 2020-12-11 18:26

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

相关标签:
1条回答
  • 2020-12-11 18:46

    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.

    0 讨论(0)
提交回复
热议问题