Jenkins/Docker Project Key points — part 4

Lamai Anthony
3 min readJun 9, 2023

--

Configure essential Jenkins plugins and create a Jenkins pipeline project

Before setting up a Jenkins CI/CD pipeline project, it is essential to ensure that the necessary Jenkins plugins are installed and up to date.

Launch Jenkins and navigate to the “Manage Jenkins” section. In Jenkins, Available Plugins tab, search for the plugin, click on “Install without restart” then wait for it to complete installing.

Sonarqube Integration:

Log in to your SonarQube instance as a user with administrative privileges. Once the token is generated, make sure to copy and securely store it in a safe location. SonarQube will only display the token once, and you won’t be able to retrieve it later. Treat the token like a password, as it grants access to your SonarQube instance.

In Jenkins go to Manage credentials and add Sonarqube user credentials/token

Configure Sonarqube Scanner in Global Tool Configuration

Add Sonarqube server under Manage Jenkins > System

Sonatype Nexus:

In the Nexus Server create the Repository.

In Jenkins go to Manage credentials and add Nexus user credentials/token. Under Manage Plugins, download Nexus artifact uploader. In the Groovy script pipeline use the “withSonarQube” plugin. Jenkins has a Pipeline Syntax tool that helps with creating the pipeline script.

Create a Jenkins pipeline project, enter a project name, and click ok. The Jenkins pipeline script can be found in my GitHub repository.

Docker:

To integrate Docker and push to DockerHub, install the Docker plugin, add the Docker credentials, and then configure Docker in the Global Tool Management menu. Check out my medium article on Docker for more information.

The Jenkins Groovy script used in this project can be found below.

pipeline {
agent any

tools {
maven 'Maven.3.8.7'
}

stages {
stage("Git Checkout") {
steps {
git branch: 'main', credentialsId: 'Github', url: 'https://github.com/Git-LAnthony/Jenkins-k8s.git'
}
}

stage("Maven Package") {
steps {
sh "mvn clean package"
}
}

stage("Sonarqube code scan") {
steps {
script{withSonarQubeEnv(credentialsId: 'sonarqube-token') {
sh "mvn clean package sonar:sonar"
}
}
}
}


stage("Nexus artifact") {
steps {
nexusArtifactUploader artifacts: [[artifactId: 'test-java-app', classifier: '', file: 'target/test-java-app.war', type: 'war']], credentialsId: 'admin', groupId: 'com.mt', nexusUrl: '54.236.49.57:8081', nexusVersion: 'nexus3', protocol: 'http', repository: 'maven-mixed-artifactory', version: '1.1.1'
}
}

stage("Docker Build") {
steps {

sh "docker build -t dockerlanthony/test-java-app:${BUILD_ID} ."
}
}

stage("Docker Push") {
steps {
withCredentials([string(credentialsId: 'Dockerhubpws', variable: 'Dockerhubpwd')]) {
sh "docker login -u dockerlanthony -p ${Dockerhubpwd}"
}
sh "docker push dockerlanthony/webapp:${BUILD_ID}"
}
}

}

Troubleshooting a failed Jenkins pipeline requires a systematic approach, utilizing the console output logs and using external resources like Google search and official documentation effectively.

--

--

Lamai Anthony
Lamai Anthony

Written by Lamai Anthony

Technical Engineer passionate about continuous learning and evolution. Always surfing the net and trying projects in search of new ideas and perspectives