DEV Community

ashutosh049
ashutosh049

Posted on • Edited on

1 1

Gitlab CI/CD


variables:
      MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
      MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
      DOCKER_DRIVER: overlay2
      #IMAGE_PATH: $CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME
      IMAGE_PATH_GITLAB: $CI_REGISTRY_IMAGE
      IMAGE_PATH_DKHUB: $DKHUB_REGISTRY/$DKHUB_REGISTRY_USER/$CI_PROJECT_NAME
      CI_BUILD_NAME: $CI_PROJECT_NAME

cache:
      key: mavenrepo
      paths:
      - ./.m2/repository

image: docker:19.03.1

services:
- docker:19.03.1-dind

stages:
      - build
      - deploy
      - push

mvn_build:
      image: maven:3.3.9-jdk-8
      stage: build
      only:
            - master
      script:
            - "mvn $MAVEN_CLI_OPTS clean install -Dmaven.test.skip=true -s ci_settings.xml"
      artifacts:
            paths:
            - target/$CI_BUILD_NAME*-exec.jar

mvn_deploy:
      image: maven:3.3.9-jdk-8
      stage: deploy
      only:
      - master
      before_script:
            - echo "Project-> [$CI_PROJECT_NAME]"
            - echo "IMAGE_PATH  = $IMAGE_PATH"
      script:
            - 'mvn $MAVEN_CLI_OPTS deploy -Dmaven.test.skip=true -s ci_settings.xml'
      when: on_success

.push_img_gitlab:
      stage: push
      only:
           - master
      before_script:
            - docker version
            - echo "IMAGE_PATH_GITLAB = $IMAGE_PATH_GITLAB"
            - docker login $IMAGE_PATH_GITLAB -u $GITLAB_REGISTRY_USER -p $GITLAB_REGISTRY_PAT
      script:
            - docker pull $IMAGE_PATH_GITLAB || true
            - docker build --tag $IMAGE_PATH_GITLAB:$CI_COMMIT_SHORT_SHA .
            - docker push $IMAGE_PATH_GITLAB:$CI_COMMIT_SHORT_SHA
      when: on_success

push_img_dockerhub:
      stage: push
      only:
            - master
      before_script:
            - docker version
            - echo "IMAGE_PATH_DKHUB = $IMAGE_PATH_DKHUB"
            - docker login -u $DKHUB_REGISTRY_USER -p $DKHUB_REGISTRY_PAT $DKHUB_REGISTRY
      script:
            - docker build --pull -t $IMAGE_PATH_DKHUB .
            - docker push $IMAGE_PATH_DKHUB
      when: on_success

Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay