Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ spec:
spec:
containers:
- name: spring-boot-app
image: abhishekf5/ultimate-cicd:replaceImageTag
image: jatinkishorem/java:replaceImageTag
ports:
- containerPort: 8080
64 changes: 39 additions & 25 deletions java-maven-sonar-argocd-helm-k8s/spring-boot-app/JenkinsFile
Original file line number Diff line number Diff line change
@@ -1,60 +1,74 @@
pipeline {
agent {
docker {
image 'abhishekf5/maven-abhishek-docker-agent:v1'
args '--user root -v /var/run/docker.sock:/var/run/docker.sock' // mount Docker socket to access the host's Docker daemon
image 'jatinkishorem/docker-maven:v1'
args '-v /var/run/docker.sock:/var/run/docker.sock -u root'
}
}

environment {
SONAR_URL = "http://54.174.95.88:9000"
DOCKER_IMAGE = "jatinkishorem/java:${BUILD_NUMBER}"
GIT_REPO_NAME = "Jenkins-Zero-To-Hero"
GIT_USER_NAME = "JatinKishore"
}

stages {
stage('Checkout') {
steps {
sh 'echo passed'
//git branch: 'main', url: 'https://github.com/iam-veeramalla/Jenkins-Zero-To-Hero.git'
checkout([$class: 'GitSCM',
branches: [[name: '*/main']],
userRemoteConfigs: [[url: 'https://github.com/JatinKishore/Jenkins-Zero-To-Hero.git']]
])
}
}

stage('Build and Test') {
steps {
sh 'ls -ltr'
// build the project and create a JAR file
sh 'cd java-maven-sonar-argocd-helm-k8s/spring-boot-app && mvn clean package'
dir('java-maven-sonar-argocd-helm-k8s/spring-boot-app') {
sh 'mvn clean package'
}
}
}

stage('Static Code Analysis') {
environment {
SONAR_URL = "http://34.201.116.83:9000"
}
steps {
withCredentials([string(credentialsId: 'sonarqube', variable: 'SONAR_AUTH_TOKEN')]) {
sh 'cd java-maven-sonar-argocd-helm-k8s/spring-boot-app && mvn sonar:sonar -Dsonar.login=$SONAR_AUTH_TOKEN -Dsonar.host.url=${SONAR_URL}'
dir('java-maven-sonar-argocd-helm-k8s/spring-boot-app') {
sh '''
mvn sonar:sonar \
-Dsonar.login=$SONAR_AUTH_TOKEN \
-Dsonar.host.url=$SONAR_URL
'''
}
}
}
}

stage('Build and Push Docker Image') {
environment {
DOCKER_IMAGE = "abhishekf5/ultimate-cicd:${BUILD_NUMBER}"
// DOCKERFILE_LOCATION = "java-maven-sonar-argocd-helm-k8s/spring-boot-app/Dockerfile"
REGISTRY_CREDENTIALS = credentials('docker-cred')
}
steps {
script {
sh 'cd java-maven-sonar-argocd-helm-k8s/spring-boot-app && docker build -t ${DOCKER_IMAGE} .'
def dockerImage = docker.image("${DOCKER_IMAGE}")
docker.withRegistry('https://index.docker.io/v1/', "docker-cred") {
dockerImage.push()
}
withCredentials([usernamePassword(credentialsId: 'docker-cred', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
dir('java-maven-sonar-argocd-helm-k8s/spring-boot-app') {
sh '''
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker build -t $DOCKER_IMAGE .
docker push $DOCKER_IMAGE
'''
}
}
}
}

stage('Update Deployment File') {
environment {
GIT_REPO_NAME = "Jenkins-Zero-To-Hero"
GIT_USER_NAME = "iam-veeramalla"
GIT_USER_NAME = "JatinKishore"
}
steps {
withCredentials([string(credentialsId: 'github', variable: 'GITHUB_TOKEN')]) {
sh '''
git config user.email "abhishek.xyz@gmail.com"
git config user.name "Abhishek Veeramalla"
git config user.email "jatinkm02@gmail.com"
git config user.name "JatinKishore"
BUILD_NUMBER=${BUILD_NUMBER}
sed -i "s/replaceImageTag/${BUILD_NUMBER}/g" java-maven-sonar-argocd-helm-k8s/spring-boot-app-manifests/deployment.yml
git add java-maven-sonar-argocd-helm-k8s/spring-boot-app-manifests/deployment.yml
Expand Down