Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab CI How to trigger pipeline for submodules in maven multi-module project

I have a multi-module Maven project:

root
    SubmoduleA
        src
        pom.xml      
    SubmoduleB
        src
        pom.xml
    pom.xml
    .gitlab-ci.yml

Is there any way I can trigger a CI pipeline only on SubmoduleA when somebody checks in code that only affects SubmoduleA? For example, someone makes a change in SubmoduleA. Once they commit and push, I want to automatically run build->test->deploy only on SubmoduleA since there were no changes to SubmoduleB.

Is there a way to specify triggers and jobs for specific sub-modules or sub-projects within a repo?

like image 988
Vince Avatar asked Sep 22 '16 20:09

Vince


2 Answers

Gitlab has a few options to build your CI/CD:

  • Basic
  • DAG
  • Child/Parent

You can mix them. They are not mutual exclusive.

You are interested in Child/Parent

stages:
  - triggers

trigger_a:
  stage: triggers
  trigger:
    include: a/.gitlab-ci.yml
  rules:
    - changes:
        - a/*

trigger_b:
  stage: triggers
  trigger:
    include: b/.gitlab-ci.yml
  rules:
    - changes:
        - b/*

Then you have to include the pipelines for a and b projects. You can find more in their documentation

like image 55
renno Avatar answered Sep 20 '22 07:09

renno


Gitlab can trigger job on catalog change: https://docs.gitlab.com/ee/ci/yaml/#onlychanges

For this solution:

  • you should enable gitlab cache for maven repository to keep previous build modules.
  • then you can define job for path change
stages:
  - modules
  - build

moduleB:
  stage: modules
  script: 
    - mvn $MAVEN_OPTS -pl projectB clean install --also-make $MAVEN_CLI_OPTS
  only:
    changes:
      - projectB/**

master_job:
  stage: build
  dependencies:
    - projectB
  script:
    - >
      mvn $MAVEN_OPTS -pl projectA clean install $MAVEN_CLI_OPTS
like image 36
x0r Avatar answered Sep 21 '22 07:09

x0r