In this guide, we will use Jenkins as a Continuous Integration server and Nexus as a build repository. The end goal of this guide is to create a flow, where we can build, store, organize and monitor the compiled artifacts by Maven through our CI server. Before we begin, make sure that you already have Jenkins up and running. In case you haven’t set up Jenkins yet, then copy the below command and run it on your Docker enabled host/machine. $ docker run -d --name jenkins-ci -p : jenkins/jenkins:lts 8080 8080 Once, Jenkins container is configured on your local/remote machine. Go to your preferred browser and open the URL . http:///your-ip-addr:8080 On the very first page, Jenkins will ask you for the admin password, which you can find by running below mentioned command in your terminal: $ docker exec -i jenkins-ci cat / /jenkins_home/secrets/initialAdminPassword b5102c8d9fa245dbb0b8da03f504d3a5 var Follow the guided steps to finish the configuration. Save the username and password securely for future use. Installing Nexus: Nexus is a repository manager that allows you to store and retrieve artifacts. It enables you to host your built artifacts in a private and secure repo. You can always pull the Nexus Docker image using the following command: $ docker pull sonatype/nexus3 Using tag: latest latest: Pulling sonatype/nexus3 cb3c77f9bdd8: Pull complete fd8daf2668d1: Pull complete fd1ff82b00e8: Pull complete a05f7b573af: Pull complete Digest: sha256: dfbc3eb094fe5cbbacec87aa8b91d16394dab627177e1deeebb5ac8ee Status: Downloaded newer image sonatype/nexus3:latest docker.io/sonatype/nexus3:latest default from 2 6570855 for Now it’s time to run downloaded sonatype/nexus on the default port 8081. Follow the below-mentioned commands: $ docker run -d --name nexus_repo -p : sonatype/nexus3 8081 8081 Usually it takes 1 to 2 minutes for the Nexus service to launch in your newly created Docker container. If you wish to follow the log to see if Nexus is up and ready, then run the following command: $ docker logs nexus_repo -f In logs you will see a message stating . It means your Nexus Repository Manager is ready to use. Now go to your browser and open . Started Sonatype Nexus OSS 3.20.1-01 http://your-ip-addr:8081 Find the option as shown below: Sign In The default username is admin, whereas to retrieve the password you need to run the following command: $ docker exec -i nexus_repo cat /nexus-data/admin.password ace93 f0d d2 b3b3a88d149 502 -5450 -4 -97 -9 And that’s it. Your Nexus Repository Manager is ready-to-use. The next step is to create a new repository. Create a Repository in Nexus: In this step, you are going to create a Maven Hosted repository in Nexus, where your Jenkins is going to upload “build” artifacts. Follow the below-mentioned steps to create a hosted repository, name it as , which you are going to use throughout this guide. Step 1: maven-nexus-repo Select recipe from the list as shown in the below-mentioned figure: maven2 (hosted) On the page, Step 2: Create Repository Enter the name as maven-nexus-repo In Version Policy, select the type of artifacts. Mixed Under the section, in , select . It will allow you to deploy an application multiple times. Hosted Deployment policy Allow redeploy To create a new user, go to . Select user type which happens to be the default Realm: Step 3: Dashboard > Server Administrator and Configuration > User > Create user Local In the page, Create User : Enter the desired ID; in our case, it is jenkins-user. ID : Enter the desired first name; in our case, it is Jenkins. First Name : Enter the desired second name; in our case, it is User. Last Name : Enter your email address. Email : Select from your drop-down menu. Status Active : Make sure that you grant the role to your user. Roles nx-admin In case you want more details for user creation, then . click here With this, we are through with the setup part of Nexus Repository Manager. Let us move to Jenkins to setup Nexus there. Install and Configure Nexus Plugins in Jenkins Here you are going to install and configure a few plugins for Nexus in Jenkins. For this, go to Jenkins and then and search and install and . Dashboard > Manage Jenkins > Manage Plugins > Available Nexus Artifact Uploader Pipeline Utility Steps Add Nexus Repository Manager’s user credentials in Jenkins. Go to , as shown below: Dashboard > Credentials > System > Global credentials (unrestricted) Next, set up Maven as a managed tool. Go to and find . Under this section, click on the button and add , as shown below: Dashboard > Manage Jenkins > Global Tool Configuration Maven Maven Installations Maven Alternatively, you can also install the Maven binary directly to your container on the directory. /var/jenkins_home Create a Jenkins Pipeline It’s time to create a Jenkins Job. Here you are going to use Pipeline job type, named as , as shown below: JenkinsNexus In the next page, find the Pipeline section and copy the below-mentioned script in the text area: pipeline { agent { label } tools { maven } environment { NEXUS_VERSION = NEXUS_PROTOCOL = NEXUS_URL = NEXUS_REPOSITORY = NEXUS_CREDENTIAL_ID = } stages { stage( ) { steps { script { git ; } } } stage( ) { steps { script { sh } } } stage( ) { steps { script { pom = readMavenPom file: ; filesByGlob = findFiles(glob: ); echo artifactPath = filesByGlob[ ].path; artifactExists = fileExists artifactPath; (artifactExists) { echo ; nexusArtifactUploader( nexusVersion: NEXUS_VERSION, : NEXUS_PROTOCOL, : NEXUS_URL, : pom.groupId, : pom.version, : NEXUS_REPOSITORY, : NEXUS_CREDENTIAL_ID, : [ [artifactId: pom.artifactId, : , : artifactPath, : pom.packaging], [artifactId: pom.artifactId, : , : , : ] ] ); } { error ; } } } } } } "master" "Maven" "nexus3" "http" "you-ip-addr-here:8081" "maven-nexus-repo" "nexus-user-credentials" "Clone code from VCS" 'https://github.com/javaee/cargotracker.git' "Maven Build" "mvn package -DskipTests=true" "Publish to Nexus Repository Manager" "pom.xml" "target/*.${pom.packaging}" "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}" 0 if "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${pom.version}" protocol nexusUrl groupId version repository credentialsId artifacts classifier '' file type classifier '' file "pom.xml" type "pom" else "*** File: ${artifactPath}, could not be found" Let’s break down the above-mentioned parameters bit by bit: : Here, we have to mention the exact version of Nexus, which can be or . In our case, it is latest version of . NEXUS_VERSION nexus2 nexus3 nexus3 : For this guide we have used HTTP protocol, although, in case of production, you will have to use HTTPS. NEXUS_PROTOCOL : Add your IP address and port number, where you are running Nexus. Make sure that you add Nexus instance details without mentioning protocols, i.e., or . NEXUS_URL https http : Enter the user ID, which you previously created in Jenkins, which in our case is . NEXUS_CREDENTIAL_ID nexus-user-credentials : Under stages, we used Project Git https://github.com/javaee/cargotracker As you are through with the Pipeline set up, it’s time to our project. Go to the project job page and click . As this is your first build, it is going to take some time, so sit tight. Build JenkinsNexus Build Now Once build is a success, in your Jenkins Console Output, you will see something like this: Whereas, in your Nexus Repository Manager, you would see something similar to this: Conclusion: A systematic way to disturb the project’s artifact is critical for any organization. With the help of Jenkins Pipeline and Nexus Repository Manager, you can centralize artifact repo, which ultimately reduces the efforts of reproducing build time as well as switch CI tools without worrying about migrating our artifacts. Nexus can be configured with cloud storage services like AWS S3 and Google Cloud Storage as well, which gives you additional freedom and delivery application without any hassle of storage. Hope you liked the article and took good use of it. You might also want to explore Configuring a CI/CD pipeline through Jenkins through . this article This article was originally published on https://appfleet.com/