Nexus 3 Overview and Installation Guide 🎯

Nexus 3 Overview and Installation Guide 🎯

Β·

5 min read

Nexus 3 is a widely used artifact repository manager developed by Sonatype. It helps teams store, manage, and retrieve binary artifacts such as JAR files, Docker images, npm packages, and more. Below, we break down its key features, installation process, and pipeline setup to manage artifacts efficiently. πŸš€


Key Features of Nexus 3 ✨

  1. Artifact Repository Manager πŸ—‚οΈ:

    • Stores and manages binary artifacts, including libraries, dependencies, and build outputs.
  2. Support for Multiple Repository Formats πŸ“¦:

    • Formats include Maven, Docker, npm, NuGet, PyPI, Yum, and more.
  3. Proxy and Caching πŸ”—:

    • Improves build performance by caching external repositories like Maven Central.
  4. Hosting Private Repositories πŸ”’:

    • Allows secure storage of proprietary or custom artifacts.
  5. Search and Indexing πŸ”:

    • Easily find artifacts using robust search capabilities.
  6. Security and Access Control πŸ”:

    • Define roles and permissions for fine-grained access control.
  7. Integration with CI/CD Tools 🀝:

    • Works seamlessly with Jenkins, Travis CI, and more for automated publishing and retrieval.
  8. Lifecycle Management πŸ”„:

    • Define retention policies and track artifact lifecycles.
  9. Monitoring and Reporting πŸ“ˆ:

    • Monitor repository health and optimize usage.
  10. RESTful API πŸ”§:

    • Automate tasks like uploading artifacts, managing repositories, and permissions.
  11. High Availability and Scalability πŸ“‘:

    • Scale horizontally and configure for high availability.
  12. User-Friendly Web Interface 🌐:

    • Manage repositories and settings via an intuitive web UI.
  13. Plugin Ecosystem 🧩:

    • Extend functionality with plugins to meet specific needs.

Installation Guide πŸ› οΈ

Linux Installation Commands πŸ’»:

sudo apt install openjdk-8-jdk -y
cd /opt
wget https://download.sonatype.com/nexus/3/nexus-3.59.0-01-unix.tar.gz
tar -xvf nexus-3.59.0-01-unix.tar.gz
adduser nexus
chown -R nexus:nexus nexus-3.59.0-01/
chown -R nexus:nexus sonatype-work/
vi nexus-3.59.0-01/bin/nexus.rc
# Add "nexus" in the file
/opt/nexus-3.59.0-01/bin/nexus start

Docker Installation Commands 🐳:

  1. Run Nexus 3 Container:

     docker run -d -p 8081:8081 --name nexus sonatype/nexus3
    
  2. Retrieve Initial Admin Password:

     docker ps
     docker exec -it <container_ID> /bin/bash
     cat sonatype-work/nexus3/admin.password
    
  3. Access Nexus Web Interface:

    • Visit http://localhost:8081 and log in with username admin and the retrieved password.
  4. Cleanup (Optional):

     docker stop nexus
     docker rm nexus
    

Setting Up Jenkins and SonarQube πŸ› οΈ

1. Set Up Virtual Machines (VMs) for Jenkins and SonarQube 🌐

  • Jenkins (Direct Install):

      sudo apt update
      sudo apt install openjdk-11-jdk -y
      sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
        https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
      echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
        https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
        /etc/apt/sources.list.d/jenkins.list > /dev/null
      sudo apt-get update
      sudo apt-get install jenkins -y
    
  • SonarQube (Docker):

      docker run -d --name sonarqube -p 9000:9000 sonarqube:lts-community
    

2. Download Plugins in Jenkins πŸ”Œ

  • Navigate to Manage Jenkins > Plugins and install:

    • Pipeline

    • Maven Integration

    • Config File Provider

    • SonarQube Scanner

    • OWASP Dependency-Check

3. Configure Tools in Jenkins βš™οΈ

  • Go to Manage Jenkins > Global Tool Configuration:

    • JDK: Add a JDK installation (e.g., JDK 17).

    • Maven: Add Maven (e.g., Maven 3.8).

    • SonarQube Scanner: Specify the installation directory.

    • OWASP Dependency-Check: Configure the tool.

4. Create and Copy Token in SonarQube πŸ”‘

  • Log in to SonarQube at http://<server_ip>:9000.

  • Navigate to My Account > Security > Generate Token and copy the token.

5. Configure SonarQube Server in Jenkins 🌐

  • Go to Manage Jenkins > Configure System > SonarQube Servers:

    • Add a new server with:

      • Name: SonarQube

      • Server URL: http://<server_ip>:9000

      • Authentication Token: Paste the generated token.

6. Create Config File in Jenkins for Authentication πŸ”

  • Use Jenkins Credentials to securely store usernames, passwords, and tokens.


Configuring Maven for Nexus πŸ› οΈ

Add the following to your pom.xml file:

<distributionManagement>
   <repository>
       <id>maven-releases</id>
       <url>NEXUS-URL/repository/maven-releases/</url>
   </repository>
   <snapshotRepository>
       <id>maven-snapshots</id>
       <url>NEXUS-URL/repository/maven-snapshots/</url>
   </snapshotRepository>
</distributionManagement>

CI/CD Pipeline for Nexus Integration πŸ”„

Here’s a detailed pipeline configuration to demonstrate how to integrate Nexus and SonarQube:

Pipeline Overview 🌟

pipeline {
    agent any
    tools {
        jdk 'jdk17'
        maven 'maven3'
    }
    environment {
        SCANNER_HOME = tool 'sonar-scanner'
    }
    stages {
        stage('Git Checkout') {
            steps {
                git 'https://github.com/Ank911007/Boardgame-java.git'
            }
        }
        stage('Code Compilation') {
            steps {
                sh 'mvn clean compile'
            }
        }
        stage('Unit Testing') {
            steps {
                sh 'mvn clean test'
            }
        }
        stage('Security Scan: Trivy') {
            steps {
                sh 'trivy fs .'
            }
        }
        stage('Dependency Check') {
            steps {
                dependencyCheck additionalArguments: ' --scan ./ ', odcInstallation: 'DC'
                dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
            }
        }
        stage('Code Quality Analysis: SonarQube') {
            steps {
                withSonarQubeEnv('Sonar-server') {
                    sh ''' $SCANNER_HOME/bin/sonar-scanner \
                        -Dsonar.projectName=BoardGame \
                        -Dsonar.java.binaries=. \
                        -Dsonar.projectKey=BoardGame '''
                }
            }
        }
        stage('Download JAR with Credentials') {
            steps {
                script {
                    withCredentials([usernamePassword(credentialsId: 'your-credentials-id', 
                        usernameVariable: 'user', passwordVariable: 'pass')]) {
                        def jarUrl = 'https://example.com/path/to/your.jar'
                        sh "curl -u $user:$pass -O $jarUrl"
                    }
                }
            }
        }
        stage('Build & Deploy to Nexus') {
            steps {
                withMaven(globalMavenSettingsConfig: 'e7838703-298a-44a7-b080-a9ac14fa0a5e') {
                    sh 'mvn deploy'
                }
            }
        }
    }
}

Summary of Pipeline Stages πŸ“

  1. Git Checkout πŸ–‡οΈ:

    • Clones the project repository.
  2. Code Compilation πŸ› οΈ:

    • Compiles the code using Maven.
  3. Unit Testing βœ…:

    • Runs tests to validate code functionality.
  4. Security Scan: Trivy πŸ›‘οΈ:

    • Scans the codebase for vulnerabilities.
  5. Dependency Check πŸ”—:

    • Identifies vulnerable dependencies in the project.
  6. Code Quality Analysis: SonarQube πŸ”:

    • Analyzes the code for quality and maintainability issues.
  7. Download JAR with CredentialsπŸ“¦:

    • download the artifact from Nexus to Jenkins Workspace using artifact link address.
  8. Build & Deploy to Nexus πŸ“¦:

    • Builds the project and deploys the artifact to Nexus.

Verification Steps πŸ•΅οΈ

  1. Verify Code Analysis in SonarQube 🧐:

    • Visit http://<server_ip>:9000 and check the project dashboard for detailed code quality metrics.

  2. Verify JAR File Uploaded in Nexus πŸ“‚:

    • Log in to Nexus at http://<server_ip>:8081.

    • Navigate to the repository (e.g., maven-releases) to confirm the artifact is uploaded.

  3. Verify JAR File Uploaded in Jenkins WorkspaceπŸ“‚:

    1. Verify JAR File Downloaded in LocalπŸ“‚:


Nexus 3, combined with Jenkins and SonarQube, simplifies artifact management and code analysis, making your CI/CD pipelines more robust and efficient. Try it today and take your DevOps workflow to the next level! πŸš€

Β