Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Config maven setting in Jenkins

My project has 3 maven module and they are built by nodejs script.

Now I want to integrate with Jenkin and Nexus. My Jenkin build config look like this:

Build configI also add my maven settings.xml in Provide configuration files build step in Build section but it didn't work. Maven still fail and could not resolve dependencies in my Nexus repo.

In my local maven settings.xml I have added some config for Nexus repository and another repository.

Can you enlight me this case. I'm new to Jenkin.

Thanks in advance.

like image 991
Anh N. Nguyen Avatar asked May 05 '17 04:05

Anh N. Nguyen


People also ask

How will you configure Maven in Jenkins?

In the Jenkins dashboard (Home screen), click Manage Jenkins from the left-hand side menu. Then, click on 'Configure System' from the right hand side. In the Configure system screen, scroll down till you see the Maven section and then click on the 'Add Maven' button. Uncheck the 'Install automatically' option.

Where is my Maven config?

The Maven settings file, settings. xml , is usually kept in the . m2 directory inside your home directory.


2 Answers

I just find a way to work around by adding mvn-settings.xml directly to my folder and edit the run command like:

mvn clean install -s mvn-settings.xml
like image 155
Anh N. Nguyen Avatar answered Oct 05 '22 14:10

Anh N. Nguyen


I came up with a solution combining the question and answer(both from Anh). The problem with Anh's solution to the problem was that we had to include the settings.xml which might contain credentials(in my case, it had some confidential information), which shouldn't be a part of repository(as highlighted in the comment by sigi).

This is how I avoided that risk(Step by step):

  1. From Jenkins home, goto Manage Jenkins > Managed Files
  2. Click on Add a new Config > Maven settings.xml > Keep the ID unedited(preferably) > Submit
  3. Provide a name for easy recognition and comment if necessary, then copy paste the xml content to the content area. Click on Submit. Adding configuration XML
  4. Goto your project's build configuration, under Build Environment section, check Provide Configuration files option.
  5. From the file dropdown, choose the file you added in step 3 above.
  6. Now the key points is to fill in the Target field. Provide a file name(or path relative to your project if you need it like that). You can also optionally fill in a variable name if you need the configuration to be used in other parts of the build configuration(These come from the Config file provider plugin). Provide configuration files
  7. Now in the Build section, provide the following command to take the settings.xml file from the checked out projects path(which jenkins copied there for you to use):
    clean install -s settings.xml

Please note that the build project I created in Jenkins was as a Maven Project.

like image 41
Harikrishnan Avatar answered Oct 05 '22 14:10

Harikrishnan