10
votes

I have two branches: master and test. When I push to the master branch, my code is deployed to the first server by gitlab-ci. I want to deploy to a different server whenever I push to the test branch. Is this possible using Gitlab CI?

  • master - 10.10.10.1
  • test - 10.10.10.2

My gitlab-ci.yml:

maven_build:
script: 
    - mvn install
    - /opt/payara41/bin/./asadmin --passwordfile /home/asadminpass --user admin undeploy myApplication-ear-1.0-SNAPSHOT
    - sudo /etc/init.d/glassfish restart
    - /opt/payara41/bin/./asadmin --passwordfile /home/asadminpass --host localhost --user admin deploy --force /home/gitlab-runner/builds/10b25461/0/myapp/myAppPrototype/myApp-ear/target/myApplication-SNAPSHOT.ear

only:
    - master
2

2 Answers

12
votes

You're on the right track with only:.

Simply create two different steps, one with only: master and one with only: test. Change the script: to deploy to a different server.

deploy_master:
  script: 
    - <script to deploy to master server>
  only:
    - master

deploy_test:
  script: 
    - <script to deploy to test server>
  only:
    - test
2
votes
only
 - dev
 - staging
 - master