Jenkins with Nexus
Jenkins with Nexus
Integrating Jenkins with artifact repositories like Nexus, Artifactory, and Docker Hub is a
crucial part of a CI/CD pipeline. These repositories are used to store and manage
artifacts such as build files, libraries, and Docker images that Jenkins produces during
the build process. Here's an overview of each tool and how to set them up with Jenkins:
1. Nexus Repository
Overview:
● Artifact Formats Supported: Maven, npm, NuGet, PyPI, Docker, and more.
● Usage: Nexus acts as a universal repository manager that stores binaries and
build artifacts.
1. Install Nexus:
○ Download and install Nexus Repository Manager from Sonatype's
website.
○ Start the Nexus server and access the Nexus web interface at
http://<your-server>:8081.
2. Configure Jenkins to Use Nexus:
○ Install Nexus Jenkins Plugin: Go to Jenkins Dashboard > Manage
Jenkins > Manage Plugins. Search for "Nexus Platform" and install it.
○ Configure Nexus Credentials: In Jenkins, navigate to Manage Jenkins
> Manage Credentials. Add Nexus credentials (username and
password).
○ Configure Maven Job to Deploy Artifacts:
■ In your Maven project's pom.xml, configure the Nexus repository
details.
■ In Jenkins, configure a job to use this Maven project and add
post-build actions to deploy artifacts to Nexus.
2. Artifactory
Overview:
● Artifact Formats Supported: Docker, Maven, npm, NuGet, PyPI, and more.
● Usage: Artifactory provides both an open-source version and a commercial
version, offering robust management and CI/CD integration features.
1. Install Artifactory:
○ Download and install Artifactory from JFrog's website.
○ Start the Artifactory server and access its web interface at
http://<your-server>:8081/artifactory.
2. Configure Jenkins to Use Artifactory:
○ Install Artifactory Jenkins Plugin: Go to Jenkins Dashboard > Manage
Jenkins > Manage Plugins. Search for "JFrog Artifactory" and install it.
○ Configure Artifactory Server: In Jenkins, go to Manage Jenkins >
Configure System. Add a new Artifactory server with its URL and
credentials.
○ Configure Jenkins Jobs to Deploy Artifacts:
■ In your Jenkins job, add Artifactory Gradle Build or Artifactory
Maven Build step, depending on your build tool.
■ Configure deployment details like repository name, snapshot policy,
and credentials in the build step.
3. Docker Hub
Docker Hub is a cloud-based repository service that allows you to store and manage
Docker images.
Overview:
Create a Jenkins Pipeline script (Jenkinsfile) with stages for building and pushing
Docker images:
groovy
pipeline {
agent any
environment {
DOCKERHUB_CREDENTIALS =
credentials('dockerhub-credentials-id')
DOCKER_IMAGE =
'your-dockerhub-username/your-repo-name'
}
stages {
stage('Build Docker Image') {
steps {
script {
dockerImage =
docker.build(DOCKER_IMAGE)
}
}
}
stage('Push Docker Image') {
steps {
script {
docker.withRegistry('',
'DOCKERHUB_CREDENTIALS') {
dockerImage.push()
}
}
}
}
}
}
Integrating Jenkins with Nexus, Artifactory, and Docker Hub helps automate the process
of building, testing, storing, and deploying software. Each tool has its own set of
features and configurations, but they all serve the purpose of managing artifacts
efficiently within a CI/CD pipeline. By following the setup steps outlined above, you can
integrate Jenkins with these repositories to create a seamless, automated build and
deployment workflow.