Saturday, May 16, 2026

How to Implement CICD Pipeline using GitLab Yaml | GitLab Actions Tutorials | GitLab CICD Pipeline | Build Java WAR file using GitLab CICD YAML file

Here below is the code for creating GitLab CICD yaml file for Java Web App project to automate build and deployment. 

stages:

  - build

  - deploy


build_war:

  stage: build

  image: maven:3.8.6-eclipse-temurin-11


  script:

    - echo "Building WAR file using Maven"

    - mvn clean install -f MyWebApp/pom.xml

    - echo "Listing target directory"

    - ls -la MyWebApp/target


  artifacts:

    paths:

      - MyWebApp/target/*.war

    expire_in: 1 hour


deploy_to_tomcat:

  stage: deploy

  image: curlimages/curl:latest


  dependencies:

    - build_war


  script:

    - echo "Deploying WAR file to Tomcat running on AWS EC2"


    - |

      curl -v -u ${TOMCAT_USER}:${TOMCAT_PASSWORD} \

      -T MyWebApp/target/MyWebApp.war \

      "http://${TOMCAT_HOST}/manager/text/deploy?path=/MyWebApp&update=true"