Skip to content

Instantly share code, notes, and snippets.

@mkutz
Last active November 12, 2018 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkutz/34aa401592f83c42f25b5ea681d41b48 to your computer and use it in GitHub Desktop.
Save mkutz/34aa401592f83c42f25b5ea681d41b48 to your computer and use it in GitHub Desktop.
Configure Maven installations in Jenkins using a post-initialization script (https://wiki.jenkins.io/display/JENKINS/Post-initialization+script)
import hudson.tasks.Maven.MavenInstallation
import hudson.tasks.Maven.MavenInstaller
import hudson.tools.InstallSourceProperty
/*
* add Maven installations to global tool configrations
*/
hudson.tasks.Maven.DescriptorImpl mavenPlugin = Jenkins.instance.getExtensionList(hudson.tasks.Maven.DescriptorImpl).first()
mavenPlugin.installations = [
new MavenInstallation('3.6.0', null, [new InstallSourceProperty([new MavenInstaller('3.6.0')])]),
new MavenInstallation('3.2.5', null, [new InstallSourceProperty([new MavenInstaller('3.2.5')])]),
new MavenInstallation('3.1.1', null, [new InstallSourceProperty([new MavenInstaller('3.1.1')])])
]
pipeline {
agent any
tools {
maven "3.2.5"
}
stages {
stage("Use maven") {
steps {
sh "mvn --version"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment