Skip to main content

Integrate Nexus with Jenkins, Automate Artifact Deployment via CI/CD

In the world of software development, Continuous Integration and Continuous Deployment (CI/CD) have become essential practices for delivering high-quality software efficiently. This document outlines the steps to integrate Nexus Repository Manager with Jenkins, enabling automated artifact deployment. By leveraging this integration, teams can streamline their build processes, manage dependencies effectively, and ensure that artifacts are readily available for deployment.

Prerequisites

Before starting the integration process, ensure you have the following:

Jenkins Installed: Make sure you have Jenkins installed and running. You can download it from the Jenkins website.

Nexus Repository Manager Installed: You can download Nexus from the Sonatype website.

Jenkins Plugins: Install the following Jenkins plugins:

Nexus Artifact Uploader

Pipeline (if using Jenkins Pipeline)

Nexus Repository: Create a hosted repository in Nexus where you will deploy your artifacts.

Step 1: Configure Nexus Repository

Log in to Nexus: Access your Nexus Repository Manager by navigating to its URL in your web browser. Create a Hosted Repository: Go to the "Repositories" section. Click on "Create repository" and select the type (e.g., Maven2 (hosted)). Configure the repository settings (name, version policy, etc.) and save. Generate a User Token: Navigate to "Administration" > "Security" > "Users". Create a new user or use an existing one with the necessary permissions to deploy artifacts. Generate an API token for this user, which will be used for authentication in Jenkins.

Step 2: Configure Jenkins

Install Required Plugins:

Go to "Manage Jenkins" > "Manage Plugins".

Search for and install the "Nexus Artifact Uploader" plugin.

Configure Nexus Credentials:

Go to "Manage Jenkins" > "Manage Credentials".

Add a new credential:

Kind: Username with password Username: Your Nexus username Password: Your Nexus API token

ID: nexus-credentials (or any identifier you prefer)

Create a New Job: Click on "New Item" in Jenkins.

Choose "Pipeline" or "Freestyle project" based on your preference. Name your job and click "OK".

Step 3: Create a Jenkins Pipeline If you are using a Pipeline job, you can define your CI/CD process in a Jenkinsfile. Below is a sample Jenkinsfile that demonstrates how to build a Maven project and deploy the artifact to Nexus.

Step 4: Run the Jenkins Job Save the Pipeline: After configuring the Jenkinsfile, save your job. Build the Job: Click on "Build Now" to trigger the pipeline. Monitor the Build: Check the console output for any errors and ensure the artifact is successfully uploaded to Nexus.

Step 5: Verify Artifact in Nexus Log in to Nexus: Go back to your Nexus Repository Manager. Navigate to Your Repository: Find the repository where you deployed the artifact. Check for the Artifact: Verify that your artifact appears in the repository with the correct version.