Maven global configuration via Groovy init script

21 views
Skip to first unread message

Kamil Dzierżanowski

unread,
Nov 9, 2018, 9:51:25 AM11/9/18
to Jenkins Users
Greetings!

I am working to migrate an entire Jenkins configuration to code, so it is dynamically reproducible.
I haven't had problems with core config and plugins so far, but I cannot find any classes or methods that would allow me to configure the "Maven Project Configuration" section in code. There's the jenkins.mvn package, but the classess and methods aren't very helpful.

I would be very grateful for any clue how to achieve this.

Best,
Kamil

Victor Martinez

unread,
Nov 9, 2018, 2:15:20 PM11/9/18
to Jenkins Users
I'd rather suggest to look at:


I'm not sure where the "Maven Project Configuration" section is but something like the below snippet might help to configure the maven tools globally:

tool:
  maven: # (4)
    installations:
    - name: "maven"
      properties:
      - installSource:
          installers:
          - maven:
              id: "3.5.4"

Cheers

Kamil Dzierżanowski

unread,
Nov 15, 2018, 9:39:42 AM11/15/18
to Jenkins Users

Thanks for inspiration, Victor!

For the record, I was mentioning a part of "Configure Jenkins" page, which turns out to probably be a part of maven-plugin. Currently it's located right above the master node config (# of executors, etc.)

The YAML config for CasC should look similar to this:

# "Maven Project Configuration" section
mavenmoduleset
:
  globalMavenOpts
: "some opts"
  localRepository
:
    perJob
:  # alternatives: default, perExecutor


Now I haven't yet successfully managet to get the plugin to work, but it is possible to do the same as Groovy init:

import hudson.maven.MavenModuleSet;
import hudson.maven.local_repo.*;

/*
 * Possible classes of the hudson.maven.local_repo package:
 * - DefaultLocalRepositoryLocator
 * - PerExecutorLocalRepositoryLocator
 * - PerJobLocalRepositoryLocator
 */


def mvnModuleSetDesc = MavenModuleSet.DESCRIPTOR;
mvnModuleSetDesc
.setGlobalMavenOpts("Some options")
mvnModuleSetDesc
.setLocalRepository(new PerJobLocalRepositoryLocator())
Reply all
Reply to author
Forward
0 new messages