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

3

14

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?

Kingcup answered 22/9, 2016 at 20:26 Comment(0)
S
3

I believe you need to create a gitlab project for that sub-module and that sub-module needs its own .gitlab-ci.yml. At that point it will be buildable inside the gitlab-ci-runner itself.

I am not an expert in Maven (or Java) but I imagine that in larger projects your submodules could become separate binary built libraries stored in your own in-house repositories. You both produce and consume jars in your build, and you serve them using Maven itself. Maven can then download for you using its built in dependency resolution and package fetching features, and that perhaps you would be better off in a large Java project build scenario with that, than with git submodules.

I do this right now in the .Net world with a custom nuget feed and the results are similar to what you're doing, in that builds happen and the build server's resources do not get wasted by source-including and recompiling those modules a second time.

Subtreasury answered 11/10, 2016 at 11:19 Comment(0)
F
3

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
Francoisefrancolin answered 27/8, 2019 at 12:32 Comment(0)
I
1

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

Irade answered 31/10, 2021 at 23:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.