简体   繁体   中英

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 root@172.18.0.23:/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/**/*"

打包和部署阶段运行模块,在我只修改根模块之前

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

I resolved my problem. Add refs instead only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM