How to Integrate Nexus Repository with Jenkins Pipeline

In this article we are going to cover How to Integrate Nexus Repository with Jenkins Pipeline.

In the world of DevOps, automation and streamlined workflows are crucial to efficiently managing software delivery pipelines. Jenkins, a widely adopted automation server, offers powerful pipeline capabilities that enable Continuous Integration (CI) and Continuous Delivery (CD). When combined with Nexus Repository, a popular artifact repository manager, it becomes even more effective. Nexus stores and manages build artifacts and dependencies, ensuring consistent and reliable access to required components across multiple environments.

This article provides a step-by-step guide on integrating Nexus with Jenkins Pipeline. By implementing this integration, you’ll be able to automate the storage and retrieval of build artifacts, improve dependency management, and optimize your CI/CD workflows.

Prerequisites

Jenkins and Sonatype Nexus Repository should be pre-installed and signed in

Create Repository in Nexus Artifactory

Create Repository in Nexus Artifactory

Click on settings symbol:

How to Integrate Nexus Repository with Jenkins Pipeline 1

Click on Repositories:

How to Integrate Nexus Repository with Jenkins Pipeline 2

Click on Create Repository:

How to Integrate Nexus Repository with Jenkins Pipeline 3

Click on maven2 (hosted):

How to Integrate Nexus Repository with Jenkins Pipeline 4

Give a Name and click on Create Repository at the bottom of the page:

How to Integrate Nexus Repository with Jenkins Pipeline 5

Integrate Nexus Repository with Jenkins Pipeline

Download the plugin (Nexus Artifact Uploader):

Manage Jenkins — > plugins — > Available Plugins — > Nexus Artifact Uploader — > install

How to Integrate Nexus Repository with Jenkins Pipeline 6

Configure the Pipeline

pipeline {
    agent any
   
    stages {
        stage('checkout') {
            steps {
                git '<git repository url>'
            }
        }
        stage('build') {
            steps {
                sh 'mvn compile'
            }
        }
        stage('test') {
            steps {
                sh 'mvn test'
            }
        }
        stage('artifact') {
            steps {
                sh 'mvn package'
            }
        }
        stage('artifact upload') {
            steps {
                nexusArtifactUploader artifacts: [[artifactId: '', classifier: '', file: 'target/SAMPLE-1.2.2.war', type: '.war']], credentialsId: 'nexus', groupId: '', nexusUrl: '3.82.171.158:8081', nexusVersion: 'nexus3', protocol: 'http', repository: 'sample', version: '1.2.2'
            }
        }
        
    }    
    
}    

You can edit the artifact ID, file, credentials, group ID, nexus url, and repository

You can see the jenkins output:

How to Integrate Nexus Repository with Jenkins Pipeline 7

After the artifact upload is done you can download the .war file from Nexus Repository

Go to Nexus website and click on Settings icon:

How to Integrate Nexus Repository with Jenkins Pipeline 8

Select Repositories:

How to Integrate Nexus Repository with Jenkins Pipeline 9

Select your Repository:

How to Integrate Nexus Repository with Jenkins Pipeline 10

Copy the URL and paste it in the browser:

How to Integrate Nexus Repository with Jenkins Pipeline 11

You can see the UI as shown below:

How to Integrate Nexus Repository with Jenkins Pipeline 12

Click on HTML index –> in –> group ID –> artifact ID –> version –> .war file

How to Integrate Nexus Repository with Jenkins Pipeline 13

If you click on your .war file the file will be downloaded

Conclusion:

Integrating Nexus with Jenkins Pipeline provides a streamlined approach to managing and deploying artifacts within a CI/CD workflow. By configuring Nexus as a repository for Jenkins, you can securely store and manage build artifacts, ensuring consistent deployment practices across environments.

This integration not only simplifies artifact management but also enhances the traceability and reliability of releases, making the development process more efficient and maintainable. Adopting Nexus in Jenkins Pipelines supports the automation and scalability essential for modern DevOps practices, contributing significantly to a robust, well-managed software delivery lifecycle.

Harish Reddy

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap