Jenkins Karate pipeline project could not execute maven goal - maven

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.

Related

How to use specific maven and jdk on Jenkins

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"
}

Looking for standard pom.xml format to execute ONLY TEST goal as "mvn surefire:test" without dependent goals 'clean, compile'

My requirement is to execute only "mvn test" command without its dependent goals and found answer as "mvn surefire:test" will do it. But when I execute using this command, I see message as 'No Test to run'.
I suspect, pom.xml need some changes to execute 'mvn surefire:test' command. Kindly share pom.xml format to be used here.

Jenkins Maven Build Step fails but runs from command line

I've been searching the web and StackOverflow for a solution. Problem is that Jenkins will not invoke mvn from the the build step. In my build step, I'm using Invoke top-level Maven targets. From the command line mvn clean install runs just fine from the directory where the POM file is located. So I believe Maven is installed correctly.
From the console I see:
[XXXX] $ cmd.exe /C "mvn -f C:\Users\XXX\XXX\XXX\pom.xml clean install && exit %%ERRORLEVEL%%"
Error message is:
'mvn' is not recognized as an internal or external command, operable program or batch file.
What I have tried:
change the settings file option to point too the settings.xml in the Maven install folder
change the global setting file option to point too the settings.xml in the Maven install folder
I've set the MAVEN_HOME environment variable in Jenkins Configure System
What I expect to happen:
Maven to build my project from the build step.
I just removed pom.xml file from the path.. it's worked ..
So try the below option

Failure at Maven clean deploy

In my Jenkins pipeline I try to build in the Maven Surefire Plugin so I can run Maven Test within the Pipeline and ignore the failure of the Test (so that the pipeline process can go on):
mvn clean deploy -Dmaven.test.failure.ignore=false
However if I try to use the command I get following error:
class org.codehaus.groovy.ast.expr.UnaryMinusExpression, with its value 'Dmaven.test.failure.ignore', is a bad expression as the left hand side of an assignment operator at line: 6 column: 51. File: WorkflowScript # line 6, column 51.
oy -Dmaven.test.failure.ignore=false
^
I don't quite understand why it won't work, can anyone explain?
Your command line call of Maven is interpreted as groovy command. This means that you made a syntax error in your groovy script.
Yo need to use the pipeline maven plugin and run the maven call with a shell step:
https://wiki.jenkins.io/display/JENKINS/Pipeline+Maven+Plugin
Example:
withMaven(
// Maven installation declared in the Jenkins "Global Tool Configuration"
maven: 'M3',
// Maven settings.xml file defined with the Jenkins Config File Provider Plugin
// Maven settings and global settings can also be defined in Jenkins Global Tools Configuration
mavenSettingsConfig: 'my-maven-settings',
mavenLocalRepo: '.repository') {
// Run the maven build
sh "mvn clean deploy -Dmaven.test.failure.ignore=false"
} // withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe reports and FindBugs reports

running maven sonar from unix

I have a mvn project. I want to run it against sonar.
e.g. the following command - mvn org.codehaus.mojo:sonar-maven-plugin:2.0:sonar
Without going in and modifying the application pom file to add sonar plugin, is there another way that I can call the mvn command and reference sonar plugin ?
I don't know how it works, but if you execute it from Jenkins with the Sonar plugin it will work without modifying your pom.xml.

Resources