Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cicd jenkans #90

Open
wants to merge 63 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
c25c963
jenkins userdata
devopshydclub Jul 1, 2023
1dc4db6
Update nexus-setup.sh
hkhcoder Jul 1, 2023
c757e03
Update pom.xml
hkhcoder Oct 16, 2023
d98cb9e
Create settings.xml
hkhcoder Oct 16, 2023
0f8fd84
Update pom.xml
hkhcoder Nov 3, 2023
cd14391
Update pom.xml
hkhcoder Nov 3, 2023
55e76b9
Update nexus-setup.sh with jdk17
hkhcoder Aug 19, 2024
6dde3d2
Update jenkins-setup.sh
hkhcoder Jan 16, 2025
d7eecca
upgrade of jdk17And21
Feb 5, 2025
6d7db82
Update pom.xml
hkhcoder Feb 25, 2025
0a3a37e
Update sonar-setup.sh
hkhcoder Feb 25, 2025
eafa623
Update nexus-setup.sh
hkhcoder Mar 5, 2025
4d70d91
update tools
ntadesse Mar 10, 2025
13e57de
test red me
ntadesse Mar 10, 2025
4582876
cicd test
ntadesse Mar 10, 2025
7461097
ci test
ntadesse Mar 10, 2025
38ab544
archiving artifacts
ntadesse Mar 10, 2025
029b6c5
} update
ntadesse Mar 10, 2025
8edd330
unit test and checkstyle scan
ntadesse Mar 10, 2025
9b04920
} update
ntadesse Mar 10, 2025
bbe1ffb
sonar scanner update
ntadesse Mar 10, 2025
71b673b
sonarscanner } update
ntadesse Mar 10, 2025
bad7f7e
quality get set
ntadesse Mar 10, 2025
4ad67f3
nexus artifact uploader
ntadesse Mar 10, 2025
9dc3f8e
post installation with slack
ntadesse Mar 10, 2025
7e63090
Update .gitignore to ignore target directory
ntadesse Mar 11, 2025
87a9284
resolving node js and dependencies
ntadesse Mar 11, 2025
31f7903
/ update on sonarqube
ntadesse Mar 11, 2025
a68170d
nodejs tool update
ntadesse Mar 11, 2025
04a5779
ansible-code
ntadesse Mar 12, 2025
c153cb4
jenkins ansible pligin configuration
ntadesse Mar 12, 2025
a28680e
nexus variable update for ansible
ntadesse Mar 12, 2025
fc54355
missing , update
ntadesse Mar 12, 2025
85f0c27
typo error fixed
ntadesse Mar 12, 2025
f16684e
pipline update
ntadesse Mar 12, 2025
5b3e156
comma error fixed
ntadesse Mar 12, 2025
01b5cad
duplicate var update
ntadesse Mar 12, 2025
8d718db
ansible update
ntadesse Mar 14, 2025
68f76f3
ansible inventory update
ntadesse Mar 15, 2025
7e270ca
ansible inventory correction in jenkins file
ntadesse Mar 15, 2025
80c09cc
host update
ntadesse Mar 15, 2025
dc17086
increase timeout
ntadesse Mar 15, 2025
28d5c35
typo error correction i-> I
ntadesse Mar 15, 2025
e9e89cd
build and time variable update
ntadesse Mar 15, 2025
4a9ef79
update version
ntadesse Mar 15, 2025
53959e7
bug fix
ntadesse Mar 15, 2025
7cc9d30
cod fix
ntadesse Mar 15, 2025
8e1763c
code sanitize
ntadesse Mar 15, 2025
1eb8181
code update
ntadesse Mar 15, 2025
2eb5a08
update inventory
ntadesse Mar 15, 2025
a76bce2
update Jenkinsfile
ntadesse Mar 15, 2025
11cda33
ssh timeout increased to 60
ntadesse Mar 15, 2025
2ac1692
credentialsId correction
ntadesse Mar 15, 2025
9205ee7
update jdk version
ntadesse Mar 17, 2025
bfd8f90
updatr ansible playbook
ntadesse Mar 17, 2025
474f45f
update
ntadesse Mar 17, 2025
b55496f
tomcat 11 -> 10
ntadesse Mar 17, 2025
943daf9
tomcat update
ntadesse Mar 17, 2025
3016553
service file update
ntadesse Mar 17, 2025
00195cd
host change
ntadesse Mar 18, 2025
8fe73e9
update login key
ntadesse Mar 18, 2025
fbe8c29
adjusting pipeline path
ntadesse Mar 18, 2025
2ddf723
pipline update
ntadesse Mar 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ignore target directory
target/

# Other files and directories to ignore
*.log
*.tmp
*.swp
*.war
*.exe
.DS_Store
node_modules/
162 changes: 86 additions & 76 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,121 +1,131 @@
def COLOR_MAP = [
'SUCCESS': 'good',
'FAILURE': 'danger',
]

pipeline {

agent any
/*
tools {
maven "maven3"
maven "MAVEN3.9"
jdk "JDK17"
nodejs "NodeJS19"
}
*/
environment {
NEXUS_VERSION = "nexus3"
NEXUS_PROTOCOL = "http"
NEXUS_URL = "172.31.40.209:8081"
NEXUS_REPOSITORY = "vprofile-release"
NEXUS_REPO_ID = "vprofile-release"
NEXUS_CREDENTIAL_ID = "nexuslogin"
ARTVERSION = "${env.BUILD_ID}"
SNAP_REPO = 'vprofile-snapshot'
NEXUS_USER = 'admin'
NEXUS_PASS = 'admin!123'
NEXUSIP = '10.0.35.182'
NEXUSPORT = '8081'
RELEASE_REPO = 'vprofile-release'
NEXUS_CEN_REPO = 'vpro-maven-central'
NEXUS_GRP_REPO = 'vprofile-maven-group'
NEXUS_LOGIN = 'nexuslogin'
NEXUS_PSW = credentials('nexuspass')
SONARSERVER = 'sonarserver'
SONARSCANER = 'sonarscanner'
}

stages{

stage('BUILD'){
steps {
sh 'mvn clean install -DskipTests'
sh 'mvn -s settings.xml -DskipTests install'
}
post {
success {
echo 'Now Archiving...'
archiveArtifacts artifacts: '**/target/*.war'
archiveArtifacts artifacts: '**/*.war'
}
}
}

stage('UNIT TEST'){
stage('UNIT TEST'){
steps {
sh 'mvn test'
sh 'mvn -s settings.xml test'
}
}

stage('INTEGRATION TEST'){
steps {
sh 'mvn verify -DskipUnitTests'
}
}

stage ('CODE ANALYSIS WITH CHECKSTYLE'){
steps {
sh 'mvn checkstyle:checkstyle'
}
post {
success {
echo 'Generated Analysis Result'
}
}
sh 'mvn -s settings.xml checkstyle:checkstyle'
}
}

stage('CODE ANALYSIS with SONARQUBE') {

environment {
scannerHome = tool 'sonarscanner4'
scannerHome = tool "${SONARSCANER}"
}

steps {
withSonarQubeEnv('sonar-pro') {
sh '''${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=vprofile \
-Dsonar.projectName=vprofile-repo \
withSonarQubeEnv("${SONARSERVER}") {
sh '''${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=vprofile-work \
-Dsonar.projectName=vprofile-work \
-Dsonar.projectVersion=1.0 \
-Dsonar.sources=src/ \
-Dsonar.java.libraries=target/vprofile-v2/WEB-INF/lib/*.jar \
-Dsonar.java.binaries=target/test-classes/com/visualpathit/account/controllerTest/ \
-Dsonar.junit.reportsPath=target/surefire-reports/ \
-Dsonar.jacoco.reportsPath=target/jacoco.exec \
-Dsonar.java.checkstyle.reportPaths=target/checkstyle-result.xml'''
}

timeout(time: 10, unit: 'MINUTES') {
}
}
stage("Quality Gate") {
steps {
timeout(time: 10, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}

stage('NexusArtifactUploaderJob') {
steps {
nexusArtifactUploader(
nexusVersion: 'nexus3',
protocol: 'http',
nexusUrl: "${NEXUSIP}:${NEXUSPORT}",
groupId: 'QA',
version: "${env.BUILD_ID}-${env.BUILD_TIMESTAMP}",
repository: "${RELEASE_REPO}",
credentialsId: "${NEXUS_LOGIN}",
artifacts: [
[artifactId: 'vproapp',
classifier: '',
file: 'target/vprofile-v2.war',
type: 'war']
]
)
}
}
}

stage("Publish to Nexus Repository Manager") {
stage('Ansible Deploy to Staging') {
steps {
script {
pom = readMavenPom file: "pom.xml";
filesByGlob = findFiles(glob: "target/*.${pom.packaging}");
echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}"
artifactPath = filesByGlob[0].path;
artifactExists = fileExists artifactPath;
if(artifactExists) {
echo "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${pom.version} ARTVERSION";
nexusArtifactUploader(
nexusVersion: NEXUS_VERSION,
protocol: NEXUS_PROTOCOL,
nexusUrl: NEXUS_URL,
groupId: pom.groupId,
version: ARTVERSION,
repository: NEXUS_REPOSITORY,
credentialsId: NEXUS_CREDENTIAL_ID,
artifacts: [
[artifactId: pom.artifactId,
classifier: '',
file: artifactPath,
type: pom.packaging],
[artifactId: pom.artifactId,
classifier: '',
file: "pom.xml",
type: "pom"]
]
);
}
else {
error "*** File: ${artifactPath}, could not be found";
}
}
ansiblePlaybook([
playbook: 'ansible/site.yml',
inventory: 'ansible/stageinventory.yml',
installation: 'ansible',
colorized: true,
credentialsId: 'sshlogin',
disableHostKeyChecking: true,
extraVars: [
USER: 'admin',
PASS: '${NEXUS_PSW}',
nexusip: '10.0.35.182',
reponame: 'vprofile-release',
groupid: 'QA',
time: "${env.BUILD_TIMESTAMP}",
build: "${env.BUILD_ID}",
artifactId: 'vproapp',
vprofile_version: "vproapp-${env.BUILD_ID}-${env.BUILD_TIMESTAMP}.war"
]
])
}
}


}


}
post {
always {
echo 'Slack Notifications.'
slackSend channel: '#jenkinscicd',
color: COLOR_MAP[currentBuild.currentResult],
message: "*${currentBuild.currentResult}:*Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} \n More info at: ${env.BUILD_URL}"
}
}
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Prerequisites
#
- JDK 11
- Maven 3
####
- JDK 17 or 21
- Maven 3.9
- MySQL 8

# Technologies
Expand Down
3 changes: 3 additions & 0 deletions ansible/stageinventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appsrvgrp:
hosts:
10.0.35.201:
19 changes: 10 additions & 9 deletions ansible/templates/ubuntu16-svcfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ After=network.target

[Service]
User=tomcat
WorkingDirectory=/usr/local/tomcat8
Environment=JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
Environment=CATALINA_HOME=/usr/local/tomcat8
Environment=CATALINE_BASE=/usr/local/tomcat8
ExecStart=/usr/local/tomcat8/bin/catalina.sh run
ExecStop=/usr/local/tomcat8/bin/shutdown.sh
Group=tomcat
WorkingDirectory=/usr/local/tomcat10
Environment="JRE_HOME=/usr/lib/jvm/java-17-openjdk-amd64"
Environment="JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64"
Environment="CATALINA_HOME=/usr/local/tomcat10"
Environment="CATALINA_BASE=/usr/local/tomcat10"
ExecStart=/usr/local/tomcat10/bin/catalina.sh run
ExecStop=/usr/local/tomcat10/bin/shutdown.sh
SyslogIdentifier=tomcat-%i
Restart=on-failure

[Install]
WantedBy=multi-user.target

WantedBy=multi-user.target
Loading