Total Pageviews

2018/01/08

[GitLab] How to build WAR file automatically

Problem
If I hope GitLab can build a WAR file when I commit source code, how to do it?
I am using Maven 3 and JDK 7 in eclipse, and using mvn clean package -U to build WAR file in eclipse.

How-To

Step 1. Add .gitlab-ci.yml to the root directory of my project, the content looks like: 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
image: maven:3-jdk-7

build:
  stage: build
  script: "mvn clean package -U"
  artifacts:
    expire_in: 1 week
    when: always
    paths:
    - target/*.war

Step 2. Add, commit and Push .gitlab-ci.yml to GitLab
Step 3. Seeing the status of your pipeline and jobs 

Reference

[1] https://docs.gitlab.com/ce/ci/quick_start/README.html
[2] https://hub.docker.com/r/library/maven/tags/

1 comment:

Unknown said...

Hi Albert,I am using the below content for my yml file,but in gitlab the build status was succcessfull in pipeline but still war file is old one not builded with new source.
gitlab-ci.yml -->file
stages:
- build
- deploy
maven-build:
image: maven:3-jdk-7
stage: build
script: "mvn clean install"
artifacts:
expire_in: 1 week
when: always
paths:
- target/*.war

deploy:
stage: deploy
when: manual
image: ruby:latest
script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
- dpl --provider=heroku --app=$HEROKU_APP_DEV --api-key=$HEROKU_API_KEY_DEV --war=target/qualifyde-0.0.1-SNAPSHOT.war