I have my own settings.xml in my workspace which will help me in getting the jars from a repo
Now I want to configure this settings.xml in the Jenkins pipeline file, how can I do that?
where/how should I add the settings.xml in the groovy file? Can someone help me with the command which will help in configuring the settingns.xml
stage('Run') {
steps {
echo 'Running....'
sh """#!/bin/bash -e
pwd
ls -al
cd sanity
mvn clean test pom.xml
ls -al """
}
}
You can use a settings flag with your maven command.
mvn clean build --settings settings.xml
Related
I have corporate Jenkins where I don't have access to Manage Jenkins option. I want to make a build of my java app using maven.
When I try to run mvn clean install:
dir("test/test2/project") {
sh "mvn clean install -Dmaven.test.skip=true"
}
I get the following error:
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/var/jenkins/workspace/test/test2/project). Please verify you invoked Maven from the correct directory.
I was trying to add mvn -f /var/jenkins/workspace/test/test2/project/pom.xml (I have pom file in the folder) but it did not work.
I also tried
withEnv(["PATH+MAVEN=${tool 'maven-3.5.0'}/bin:${env.JAVA_HOME}/bin"]) {
sh "mvn --batch-mode -V -U -e clean install -Dmaven.test.skip=true"
which also did not work.
I would like to point to maven and java which are installed on the agent but can't seem to sucseed.
Any idea?
Can you try something like below?
dir("test/test2/project") {
sh "mvn clean install"
}
Error message from the Jenkins console:
The goal you specified requires a project to execute but there is no
POM in this directory
(/home/jenkins/workspace/Dealer-API-v2-test-automation_qa). Please
verify you invoked Maven from the correct directory.
Maven command in the Jenkins file:
sh script : "mvn test '-Dkarate.options=--tags #regression' -Dtest=TestParallel -DargLine='-Dkarate.env=qa'"
How can I execute this maven command in my pipeline script?
Just a guess but if you add -f Dealer-API-v2-test-automation_qa/pom.xml or something like that, it may start working. Or do a cd Dealer-API-v2-test-automation_qa, before doing mvn test, hope that helps.
Running: Pipeline Maven Integration Plugin 3.8.1
https://wiki.jenkins.io/display/JENKINS/Pipeline+Maven+Plugin
If I create a global config file and add a <servers> config to it with the creds hard coded this works:
In my pipeline I use it:
withMaven(
mavenSettingsConfig: 'test') {
sh """#!/bin/bash
mvn help:effective-settings -X
mvn deploy
"""
}
The output of mvn help:effective-settings -X shows my <servers> setting
BUT if I try to use a credential to securely store my creds this does not work:
The output of mvn help:effective-settings -X shows NO <servers> setting at all
Is this a bug with the plugin?
Why are you calling bash to execute Maven:
withMaven(
mavenSettingsConfig: 'test') {
sh """#!/bin/bash
mvn help:effective-settings -X
mvn deploy
"""
}
why not simply going:
withMaven(
mavenSettingsConfig: 'test') {
sh "mvn help:effective-settings deploy"
}
and no the issue must be somewhere else cause I'm using this also for a very long time...(I would try to remove the whole comment stuff..).
Please follow up on https://issues.jenkins-ci.org/browse/JENKINS-59567 where the problem was cross posted
I am creating Jenkins Slave on the fly configuring it on AWS with Spot Instances.
In the global tool configuration, I have set to use my own "settings.xml" for the master is working perfectly.
But when the server start slaves (without maven installed) it auto install maven (set in the Jenkins file to install this tool) but without putting any settings.xml
*I know I can copy the setting.xml directly from the server but for me looks like it is not the appropriate way to do it.
* I already did mvn -X in order to see find the folder for the settings but this is not used.
Added one small slice of the jenkinsfile
pipeline {
tools{
maven 'maven default'
}
agent any
stages {
stage('Maven build') {
steps {
sh 'mvn clean install'
}
}
}
}
You have to use withMaven() in the Pipeline code..which has to look like this:
withMaven(jdk: jdkName, maven: MavenInGlobalToolsName, mavenSettingsConfig: 'IdInConfigFileProvided', mavenLocalRepo:".repository") {
sh "mvn clean verify"
}
The IdInConfigFileProvided is the important part which makes the reference to the config file provider plugin...
The other solution could be to use the config file provider directly in Jenkins file:
configFileProvider(
[configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn -s $MAVEN_SETTINGS clean package'
}
But this solution will not handle the support global tools support for Maven itself. So I would suggest to prefer the withMaven() solution.
I have more than 1 settings.xml file and I want to specify the 1 I want to use when I run > mvn from the command line, because running mvn help:effective-settings is showing 1 file but it seems that is using the other one
Use:
mvn --settings settingsYouWant.xml clean install
If you add the argument -X to your maven command (debug) you can see which one is picking.