Can we deploy into different environments from the same branch?

We want to migrate our CI/CD server which is currently in Jenkins to TravisCI. But are facing few challenges.

Our current deployment process is that we are using master branch to deploy into different environments i.e dev, uat and prod. Once a PR is merged into master, then a build and deploy-dev jobs run automatically. When the team is happy with dev env, they go to Jenkins and trigger uat-deploy or prod-deploy manually which deploys it into further envs from the same master branch. There is Jenkinsfile.dev, Jenkinsfile.uat and Jenkinsfile.prod for its own environment where we set env specific variables and deploy accordingly.

Is the above flow not possible in TravisCI.

I have read the documentation of TravisCI and many other examples, where people have to put conditional statements in a single travis.yml file to deploy to different env. In every example, people are creating different branches for each environment and deploying with the conditional statements, for eg

deploy:
  - provider: script
    script: deploy_production.sh
    on:
      branch: production
  - provider: script
    script: deploy_staging.sh
    on:
      branch: staging

We dont want to create seperate branch for each env. Can’t we deploy to different env from the same master branch? If not why this approach is taken by Travis CI.

From what I can see, the problem you are stuck at is how to trigger a deploy manually, without any additional commits.

There are two options here:

  • Trigger a custom build with a custom config alteration that would trigger the additional deploy logic. The caveat here is that a custom build can only be triggered for a branch tip, not an arbitrary commit.

    • travis.yml:
      deploy:
        - provider: script
          script: deploy_production.sh
          on:
            condition: $DEPLOY_PROD == 1
        - provider: script
          script: deploy_uat.sh
          on:
            condition: $DEPLOY_UAT == 1
      
    • custom config:
      merge_mode: deep_merge
      env:
        global:
          - DEPLOY_PROD=1
          - DEPLOY_UAT=1
      
  • Tag the commit (which would trigger a tag build) and make your deploy logic be triggered by the tag presence and/or name:

    deploy:
      - provider: script
        script: deploy_production.sh
        on:
          - tags: true
          - condition: $TRAVIS_TAG =~ ^prod
      - provider: script
        script: deploy_uat.sh
        on:
          - tags: true
          - condition: $TRAVIS_TAG =~ ^uat
    
Imprint