-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Naveen
committed
Nov 16, 2023
1 parent
336853e
commit 0354425
Showing
1 changed file
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,70 @@ | ||
hi | ||
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 | ||
} | ||
} | ||
stages { | ||
stage('Checkout') { | ||
steps { | ||
sh 'echo passed' | ||
//git branch: 'main', url: 'https://github.com/iam-veeramalla/Jenkins-Zero-To-Hero.git' | ||
} | ||
} | ||
stage('Build and Test') { | ||
steps { | ||
sh 'ls -ltr' | ||
// build the project and create a JAR file | ||
sh 'mvn clean package' | ||
} | ||
} | ||
stage('Static Code Analysis') { | ||
environment { | ||
SONAR_URL = "http://100.64.188.234:9000" | ||
} | ||
steps { | ||
withCredentials([string(credentialsId: 'sonarqube', variable: 'SONAR_AUTH_TOKEN')]) { | ||
sh 'mvn sonar:sonar -Dsonar.login=$SONAR_AUTH_TOKEN -Dsonar.host.url=${SONAR_URL}' | ||
} | ||
} | ||
} | ||
stage('Build and Push Docker Image') { | ||
environment { | ||
DOCKER_IMAGE = "naveensmily79/ultimate-cicd:${BUILD_NUMBER}" | ||
// DOCKERFILE_LOCATION = "java-maven-sonar-argocd-helm-k8s/spring-boot-app/Dockerfile" | ||
REGISTRY_CREDENTIALS = credentials('docker-cred') | ||
} | ||
steps { | ||
script { | ||
sh 'docker build -t ${DOCKER_IMAGE} .' | ||
def dockerImage = docker.image("${DOCKER_IMAGE}") | ||
docker.withRegistry('https://index.docker.io/v1/', "docker-cred") { | ||
dockerImage.push() | ||
} | ||
} | ||
} | ||
} | ||
stage('Update Deployment File') { | ||
environment { | ||
GIT_REPO_NAME = "jenkins-cicd-k8s" | ||
GIT_USER_NAME = "naveen-hub79" | ||
} | ||
steps { | ||
withCredentials([string(credentialsId: 'github', variable: 'GITHUB_TOKEN')]) { | ||
sh ''' | ||
git config user.email "naveen.xyz@gmail.com" | ||
git config user.name "Naveen Chevulamaddi" | ||
BUILD_NUMBER=${BUILD_NUMBER} | ||
cp manifests/deploy-template.yaml manifests/maven-app-deploy.yaml | ||
sed -i "s/replaceImageTag/${BUILD_NUMBER}/g" manifests/maven-app-deploy.yaml | ||
git add manifests/maven-app-deploy.yaml | ||
git commit -m "Update deployment image to version ${BUILD_NUMBER}" | ||
git push https://${GITHUB_TOKEN}@github.com/${GIT_USER_NAME}/${GIT_REPO_NAME} HEAD:main | ||
''' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|