top of page
Writer's pictureSuraj Dhakre

A Step-by-Step Guide to Pushing Docker Artifacts to Nexus from Jenkins

Introduction: Understanding the Importance of Streamlining Your Workflow

In today's fast-paced and competitive business environment, it is crucial to have a streamlined workflow that allows for efficient and effective project management. A simplified workflow not only saves time and resources but also improves productivity and reduces errors. One of the key components of a streamlined workflow is effective artifact management, which involves the storage, retrieval, and distribution of software artifacts. This is where tools like Jenkins and Nexus come into play. Jenkins is an open-source automation server that allows for the continuous integration and delivery of software projects. It provides a platform for building, testing, and deploying applications, making it an essential tool for streamlining the development process. Nexus, on the other hand, is a repository manager that helps manage and distribute software artifacts. It provides a central location for storing and retrieving artifacts, ensuring that the right versions are used in the development process.

jenkins nexus

Setting Up Jenkins and Nexus: A Comprehensive Guide

Before diving into the configuration process, it is important to have a clear understanding of what Jenkins and Nexus are and how they work together. Jenkins is a Java-based automation server that allows for the continuous integration and delivery of software projects. It provides a platform for building, testing, and deploying applications, making it an essential tool for streamlining the development process. Nexus, on the other hand, is a repository manager that helps manage and distribute software artifacts. It provides a central location for storing and retrieving artifacts, ensuring that the right versions are used in the development process. By integrating Jenkins with Nexus, developers can automate the process of pushing artifacts to Nexus, ensuring that the latest versions are always available for use. To set up Jenkins and Nexus, you will need to follow a series of steps. First, you will need to setup Jenkins on your server. You can follow the guide here for the jenkins setup. Next, you will need to setup Nexus on your server. Once done, you will need to configure Nexus to connect to your Jenkins server. This will allow Nexus to receive artifacts from Jenkins and store them in its repository. By integrating Jenkins and Nexus, you can ensure that the latest versions of your artifacts are always available for use.

Step 1: Create a new blob storage for our docker image. Here we have created a new blob storage with name - docker.

nexus blob store

Step 2: Create a hosted repository to hold our docker images.

nexus repo wizard

Here we have created docker(hosted) registry with name privatedocker.

nexus docker registry


Configuring Jenkins to Push Artifacts to Nexus: Step-by-Step Instructions

Once you have set up Jenkins and Nexus, you will need to configure Jenkins to push artifacts to Nexus. This involves configuring Jenkins to build your applications and then push the resulting artifacts to Nexus. To do this, you will need to follow a series of steps. First, you will need to create a new Jenkins job for your application. This job will define the steps that Jenkins should take to build and test your application. You can specify the source code repository, build tools, and other parameters in the job configuration.

Here first we created jenkins secret with username and password. This will hold nexus authentication credentials. Now we will create a freestyle jenkins job. This step will define the commands that Jenkins should execute to build your application. You can specify the build tools, dependencies, and other parameters in the build step configuration. Below is the screenshot for reference.


jenkins job nexus 1

jenkins job nexus 2

Finally, you will need to configure the Nexus repository in your Jenkins job. This involves specifying the URL, credentials, and other parameters for the Nexus repository. Once configured, Jenkins will be able to push artifacts to Nexus whenever a build is triggered.

Error

Before you trigger your build, let's fix an upcoming issue. The error is Error response from daemon: Get "192.168.29.234:8082/v2" : http: server gave HTTP response to HTTPS client.


Cause of Error

The dockerhosted-repo is insecure, it doesn't use HTTPS protocol and docker daemon is not letting us access this insecure repository because it might be harmful for our system.


Fix

Create /etc/docker/daemon.json file where jenkins is hosted. Add below content to the file.

{ 
"insecure-registries": ["192.168.29.234:8082"] 
}

Now restart docker.

sudo systemctl restart docker

Use docker info command to check if Insecure Registries have the updated value.



Testing Your Workflow: Best Practices and Troubleshooting Tips

Once you have configured Jenkins to push artifacts to Nexus, it is important to test your workflow to ensure that everything is working as expected. Testing your workflow involves running a build in Jenkins and verifying that the artifacts are pushed to Nexus correctly. To test your workflow, you can trigger a build in Jenkins by making a change to the codebase or manually triggering a build. Once the build is complete, you can check the Nexus repository to verify that the artifacts have been pushed correctly. When testing your workflow, it is important to follow best practices to ensure accurate results. One best practice is to use a separate test environment for testing your workflow. This will allow you to isolate any issues that may arise during testing and prevent them from affecting your production environment. Another best practice is to use version control for your codebase. This will allow you to easily revert any changes that may have caused issues during testing and ensure that your codebase is always in a stable state. If you encounter any issues during testing, there are several troubleshooting tips that you can follow. One tip is to check the Jenkins and Nexus logs for any error messages or warnings. These logs can provide valuable information about what went wrong and how to fix it. Another tip is to check the configuration settings in Jenkins and Nexus. Make sure that all the necessary parameters are set correctly and that there are no typos or errors in the configuration files.

nexus browser


Automating Your Workflow: Advanced Techniques for Efficiency and Productivity

Once you have tested your workflow and ensured that everything is working as expected, you can start exploring advanced techniques for automating your workflow. Automation can help improve efficiency and productivity by reducing manual tasks and eliminating human error. One advanced technique for automating your workflow is to use Jenkins pipelines. Pipelines allow you to define your entire build process as code, making it easier to manage and version control. With pipelines, you can define multiple stages, each with its own set of steps and conditions. Another advanced technique is to use Jenkins plugins. Plugins extend the functionality of Jenkins and allow you to integrate with other tools and services. There are plugins available for almost every aspect of the development process, from source code management to deployment. Automation can also be achieved by using scripts and command-line tools. By writing scripts and using command-line tools, you can automate repetitive tasks and perform complex operations with a single command.

Conclusion: A Simplified Workflow for Better Results

In conclusion, streamlining your workflow is essential for achieving better results in your development projects. By using tools like Jenkins and Nexus, you can automate the process of building, testing, and deploying applications, saving time and resources. Setting up Jenkins and Nexus involves a series of steps, including installing and configuring the tools. Once set up, you can configure Jenkins to push artifacts to Nexus, ensuring that the latest versions are always available for use. Testing your workflow is important to ensure that everything is working as expected. Following best practices and troubleshooting tips can help you identify and resolve any issues that may arise during testing. Finally, embracing advanced techniques for automation can further improve efficiency and productivity. By using Jenkins pipelines, plugins, scripts, and command-line tools, you can automate repetitive tasks and perform complex operations with ease. In conclusion, by embracing a simplified workflow and implementing the steps outlined in this article, you can achieve better results in your development projects. Streamlining your workflow not only saves time and resources but also improves productivity and reduces errors. So why wait? Start streamlining your workflow today for better results tomorrow.

Comments


bottom of page