Infrastructure with maven, Jenkins, Nexus

Paul Verest picture Paul Verest · Aug 5, 2011 · Viewed 40.3k times · Source

We are using maven. I want to set up infrastructure, so that automatically built artifacts would go to Nexus repository. And then they could be used by developers.

I have already set up Jenkins with 1 job for our project. And I set up Nexus to on the same server.

On developers' PCs I copied default maven setting to C:\Users{user}.m2\settings.xml adding this section. References:

Configuring Maven to Use a Single Nexus

Maven Settings Reference

<mirror>
  <!--This sends everything else to /public -->
  <id>nexus</id>
  <mirrorOf>*</mirrorOf>
  <url>http://myserver:8081/nexus/content/groups/public</url>
</mirror>

(I just follow Repository Management with Nexus book)

What are my next steps should be? Should Jenkins job have mvn install? How to create Nexus repository for company artifacts?

Answer

Ryan Stewart picture Ryan Stewart · Aug 5, 2011

To deploy artifacts to Nexus, you'll need to include a distributionManagement section in your pom. Nexus ships with specific repositories already set up for both snapshots and releases. You should give the correct path to each of those so that maven will deploy snapshot and release artifacts to the correct repos. Then any time you deploy artifacts--typically with mvn deploy or using the maven release plugin, the artifacts will be deployed there. Nexus has write authentication on by default, so you'll need to make sure to add a server section with the correct credentials to the settings.xml of anyone who will be deploying artifacts. Jenkins can be treated pretty much like any other user. If you have it do a deploy as its build, then every build will deploy to Nexus. There's also a post-build action for deploying artifacts in case you want it to happen later in the Jenkins job.