Discussion:
Maven global configuration via Groovy init script
Kamil Dzierżanowski
2018-11-09 11:28:10 UTC
Permalink
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
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/de8cba4c-8e16-4697-bdc6-6ec77b5c136c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Victor Martinez
2018-11-09 19:15:19 UTC
Permalink
I'd rather suggest to look at:
- https://github.com/jenkinsci/configuration-as-code-plugin


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
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/417c30d7-185b-44b3-8b02-281da706d96d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Kamil Dzierżanowski
2018-11-15 14:39:42 UTC
Permalink
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())
Post by Victor Martinez
- https://github.com/jenkinsci/configuration-as-code-plugin
I'm not sure where the "Maven Project Configuration" section is but
something like the below snippet might help to configure the maven tools
maven: # (4)
- name: "maven"
id: "3.5.4"
Cheers
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/d87b2f20-9487-4039-bade-848b5944e5d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...