I have a maven project that resolves some of its dependencies from a private repository (Nexus) inside the company network. Therefore it can only be build using a custom settings.xml where credentials for the private repository are stored.
The maven project is built by Jenkins using a declarative pipeline. The build job is a multibranch pipeline.
In the job configuration in Jenkins, under "Pipeline Maven Configuration", I specified both a settings file (managed file) and a global settings file.
However, the pipeline itself seems to completely ignore this setting.
It seems for the custom settings.xml to be used, I have to wrap every single mvn call into either a withMaven() {...} block or a configFileProvider () {...} block.
When I do this, it's working fine, but since there are a lot of mvn calls in this pipeline, this would make the pipeline unnecessarily complex.
Is there another way of making maven pick up the custom settings.xml file?
What's the point of the "Pipeline Maven Configuration" setting anyway if the specified files aren't used without further configuration inside the pipeline?
At the moment I'm going with the following approach...
Placed my maven user settings file right next to the Jenkinsfile in my SCM. Declared the Maven to use in the "tools" section of the jenkinsfile:
tools {
maven 'Maven 3.6.3'
jdk 'AdoptOpenJDK_8u222'
}
Then I added the user settings to every maven call using the "-s" command line option:
steps {
sh 'mvn pmd:pmd -s usersettings.xml'
}
Still not happy about repeatedly adding the user settings, but leaner than running "withMaven()" - and faster.
Update
It is possible to wrap the Maven call with a Groovy function like this
def mvn(String cmd) {
sh "mvn ${cmd} -s usersettings.xml"
}
to declutter the Pipeline script:
steps {
mvn 'pmd:pmd'
}
Other way is using Pipeline Maven Integration
https://github.com/jenkinsci/pipeline-maven-plugin
node {
stage ('Build') {
git url: 'https://github.com/cyrille-leclerc/multi-module-maven-project'
withMaven(
// Maven installation declared in the Jenkins "Global Tool Configuration"
maven: 'maven-3', // (1)
// Use `$WORKSPACE/.repository` for local repository folder to avoid shared repositories
mavenLocalRepo: '.repository', // (2)
// Maven settings.xml file defined with the Jenkins Config File Provider Plugin
// We recommend to define Maven settings.xml globally at the folder level using
// navigating to the folder configuration in the section "Pipeline Maven Configuration / Override global Maven configuration"
// or globally to the entire master navigating to "Manage Jenkins / Global Tools Configuration"
mavenSettingsConfig: 'my-maven-settings' // (3)
) {
// Run the maven build
sh "mvn clean verify"
} // withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe & FindBugs & SpotBugs reports...
}
}
Related
I'm new to VSTS. We are about to start using VSTS as our repository for code and build process. Can I have a repository in VSTS where I can load all jars (like maven) and then use the same to build my java application? Basically, I'm trying to get Maven feature with VSTS
You can put jar files in the VSTS repository but needs to clone them to the build agent.
To clone extra repository, you can add Command Line step/task to call git clone command.
On the other hand, there is Maven step/task already. Build your Java app with Maven
I have a project on Github and I have set a release with a Jar for that project. I want to include this Jar in another project as an SBT dependency. How do I set up the resolvers to look for my jar in the github repo.
You want to release your jar into a repository. One option I would recommend is bintray, see bintray-sbt which is an sbt plugin for publishing to bintray, and details how to setup your second project to fetch the publish artifact.
We use Gradle to build our projects and to manage our dependencies. We want to reuse our legacy Ivy repository which is filesystem based. Our convention was to have several artifacts per module - one of them being a source artifact.
The normal jars are perfectly managed by the Gradle Eclipse integration. But we are not shown the source artifacts. Are there any conventions for this kind of setting, e.g. name of the source artifacts?
artifactName-sources.jar should work, as should defining a configuration named sources (and assigning sources artifacts to that configuration) in the iyy.xml.
i am using jenkins for automation builds.
my issue is i want to download sources from svn and run the build steps and after running the builds steps once again i want to take latest sources from svn.
is there any plugin for it where my requirement satisfy.
Consider setting up two jobs (A and B) with a shared workspace (job > configure > Advanced Project Options ; click button Advanced...). check custom workspace and define a location). Once job A is finished it triggers job B and job B then performs a svn update plus whatever else you need. In order to avoid parallel execution of A and B, check Block build when upstream project is building and Block build when downstream project is building.
Maybe not a plugin, but you can always run manual SVN commands as part of the build step
Add a new build step to "Execute shell" (if on Linux) or "Execute Windows batch command"
(if on Windows).
Inside, write SVN commands, depending on your OS, for example:
svn up checkout_folder, note that path will be relative to Jenkin's workspace
How do I configure m2eclipse ( maven plugin for eclipse ) to use a centralized maven repository that is also used in jenkins.
The default user settings in m2eclipse is something like "home/user/.m2"
How can we do something like "ssh user#192.168.1.200:/var/lib/jenkins/.m2"?
A neat and easy way to do it is to use a repository manager. Sonatype's Nexus seems to be the most popular, but there are others (e.g. JFrog Artifactory and Apache Archiva). They run as HTTP servers, and you can change your Maven configuration (both locally and for Jenkins) to use it as a mirror for any Maven repository (e.g. the Central Maven repo), or use it to host your own repositories.
There is no need to do that. Your POM files list dependencies and they list repositories. Maven will then resolve your dependencies against all known repositories (the listed ones and the "build-in" ones, like Maven central).
Maven will do this in m2eclipse, when running a Maven build. Maven will also do that when running the build on Jenkins. So if both machines can connect to all the repositories listed in your POM files, both will retrieve the same artifacts and both will do the same builds.
You should really not try to share the local copy of the artifacts. That is as bad as if I and you try to share our Maven artifacts using a network share. Maven is designed to find and manage those artifacts and you are trying to do its job with this question.