Ahmed Hammad
Ahmed Hammad

Reputation: 669

How to Specify subfolder for Maven in Jenkins?

I have the following folder structure:

The GIT repository is created on Finance folder. I configured Jenkins to look at GIT repository in /Finance. The maven pom file is located in Finance/Code. When I run the Jenkins build, I got this error:

[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/Users/Macpro/.hudson/jobs/Publishing/workspace). Please verify you invoked Maven from the correct directory. -> [Help 1]

How to configure Jenkins to look at /Finance/Code for the pom file?

Upvotes: 3

Views: 9560

Answers (3)

nautilusvn
nautilusvn

Reputation: 665

Starting from Jenkins 2.0, you can use the DSL method 'dir' to change to a subfolder, the script in pipeline looks like following:

...
stage('Compile') {
  steps {
    dir('Code') {
      sh "mvn clean compile"
    }
  }
}
...

Upvotes: 0

VonC
VonC

Reputation: 1323823

As illustrated by this question, you should fill out the Root POM field with a relative path:

root pom

Relative means from the Jenkins workspace:

Code/pom.xml

(no leading /) That is, if Finance is the root of your workspace.

Upvotes: 5

Ahmed Hammad
Ahmed Hammad

Reputation: 669

The last answer worked for me, but the settings image is a little bit different as I am using the latest version of Jenkins. So I am posting it here as it may help someone. enter image description here

Upvotes: 1

Related Questions