Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab CI multiple branches

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
like image 369
user3723340 Avatar asked Mar 30 '18 06:03

user3723340


People also ask

Can you have multiple GitLab CI files?

No, you can't have multiple gitlab-ci files per repository.

Can a GitLab project have multiple pipelines?

GitLab CI/CD is a powerful continuous integration tool that works not only per project, but also across projects with multi-project pipelines. Multi-project pipelines are useful for larger products that require cross-project inter-dependencies, such as those adopting a microservices architecture.

Can GitLab pipeline run in parallel?

GitLab CI allows you to run tests much faster thanks to CI parallelisation feature. You can run parallel jobs across multiple GitLab Runners. In order to do it, you will learn how to split tests in a dynamic way across parallel tasks to ensure there is no bottleneck in GitLab Pipeline.

What are branch pipelines in GitLab?

You can configure your pipeline to run every time you commit changes to a branch. This type of pipeline is called a branch pipeline. Alternatively, you can configure your pipeline to run every time you make changes to the source branch for a merge request. This type of pipeline is called a merge request pipeline.


2 Answers

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
like image 62
dbrekelmans Avatar answered Oct 26 '22 07:10

dbrekelmans


only
 - dev
 - staging
 - master
like image 36
larry-troy Avatar answered Oct 26 '22 08:10

larry-troy