Robert Labuda
Robert Labuda

Reputation: 1

Gitlab CI problem with merge request and multiple modules on JAVA project

I've problem with Gitlab CI pipeline if I commit and push like below. My pipeline run build, test exactly that module what I modified, but after merge pipeline runs package and deploy all modules, even these modules which have nothing new in repository.

Rob

.gitlab-ci.yml

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=.m2"
  MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version"

cache:
  paths:
    - /root/.m2/

stages:
  - build
  - test
  - package
  - deploy

include:
  - local: root/.gitlab-ci.yml
  - local: abreg/.gitlab-ci.yml

.build-module:
  stage: build
  script:
    - echo "Building $MODULE"
    - mvn -pl $MODULE clean compile --also-make
  artifacts:
    expire_in: 10 min
    paths:
      - "*/target"

.test-module:
  stage: test
  script:
    - echo "Testing $MODULE"
    - mvn $MAVEN_CLI_OPTS -pl $MODULE test --also-make

.package-module:
  stage: package
  script:
    - echo "Packing $MODULE "
    - mvn -pl $MODULE package -U --also-make
  artifacts:
     expire_in: 10 min
     paths:
       - "*/target/*.war"
  only:
    - merge_requests

.deploy-module:
  stage: deploy
  before_script:
    - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - ssh-keyscan 172.18.0.23 >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
  script:
   - scp -o StrictHostKeyChecking=no */target/*.war [email protected]:/test
  only:
    - merge_requests

#BUILD JOBS

build-root-module:
  extends:
    - .root-module
    - .build-module

build-abreg-module:
  extends:
    - .abreg-module
    - .build-module

#TEST JOBS

test-root-module:
  extends:
    - .root-module
    - .test-module

test-abreg-module:
  extends:
    - .abreg-module
    - .test-module

#PACKAGE JOBS

package-root-module:
  extends:
    - .root-module
    - .package-module

package-abreg-module:
  extends:
    - .abreg-module
    - .package-module

#DEPLOY JOBS

deploy-root-module:
  extends:
    - .root-module
    - .deploy-module

deploy-abreg-module:
  extends:
    - .abreg-module
    - .deploy-module

in root module .gitlab-ci.yml

.root-module:
  variables:
    MODULE: "root"
  only:
    changes:
      - "root/**/*"

in abreg module .gitlab-ci.yml

.abreg-module:
  variables:
    MODULE: "abreg"
  only:
    changes:
      - "abreg/**/*"

Package and deploy stages runs module, before I modify only root module

How can I modify my .gitlab-ci.yml file to achive pipeline which run only these modules which I surerly changed?

Upvotes: 0

Views: 595

Answers (1)

Robert Labuda
Robert Labuda

Reputation: 1

I resolved my problem. Add refs instead only.

Upvotes: -1

Related Questions