Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to change the working directory of a Jenkins Maven build?

Tags:

jenkins

Is there any way to change the working directory of a Jenkins Maven build?

Use Case

There is a Maven build that will only work if the current working directory is the directory with pom.xml in it, so I want the Maven build to execute in that directory.

The directory with the pom.xml is in a subdirectory of a git project.

like image 778
Max Nanasy Avatar asked Jun 26 '13 03:06

Max Nanasy


People also ask

Where do I put pom xml Path in Jenkins?

In the build section you'll find an option for adding your pom. xml file. Add the path of your pom. xml file and then apply and save.


2 Answers

Create a target to checkout the parent.

  • Checkout the parent dir of your build target
  • Set Build -> Goal = clean
  • Run build and ascertain the destination workspace directory (second line of console output, in my sample /var/lib/jenkins/workspace/my_project)

Create a target to build your path

  • DO NOT check "Delete workspace before build starts"
  • In Build -> Advanced - Check "Change folder of workspace" and paste your /yourtargetdirectory

It worked for me.

like image 134
ton Avatar answered Oct 18 '22 09:10

ton


Not sure when this was added, but for the Jenkins in front of me (Jenkins ver. 1.627 per the bottom of the page), there's now an option for defining where the root pom.xml is (help message says:

If your workspace has the top-level pom.xml in somewhere other than the 1st module's root directory, specify the path (relative to the module root) here, such as parent/pom.xml. If left empty, defaults to pom.xml

). I was facing the same issue but then realized the answer was staring me in the face (note that I did not have to hit advanced as Hua2308 suggested, probably because they changed the UI)

like image 45
Foon Avatar answered Oct 18 '22 08:10

Foon