pipeline{
agent{
docker{
image 'abhishekf5/maven-abhishek-docker-agent:v1'
args '--user root -v /var/run/docker.sock:/var/run/docker.sock'
}
}
environment {
AWS_ACCOUNT_ID="386288228052"
AWS_DEFAULT_REGION="eu-west-1"
IMAGE_REPO_NAME="inspectorv2"
IMAGE_TAG="${BUILD_NUMBER}"
REPOSITORY_URI = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${IMAGE_REPO_NAME}"
}
stages {
stage('Checkout') {
steps {
sh 'echo passed'
checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[credentialsId: 'CICD-GITusercredforcodecommit1', url: 'https:
}
}
stage('Build and Test') {
steps{
sh 'cd java-maven-sonar-argocd-helm-k8s/spring-boot-app && ls -ltr'
sh 'cd java-maven-sonar-argocd-helm-k8s/spring-boot-app && mvn -X clean package'
sh 'cd java-maven-sonar-argocd-helm-k8s/spring-boot-app && ls -ltr'
}
}
stage('Static Code Analysis') {
environment {
SONAR_URL = "http://34.241.36.33: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}'
}
}
}
stage('Building image') {
steps{
script {
sh 'cd java-maven-sonar-argocd-helm-k8s/spring-boot-app && docker build -t ${IMAGE_REPO_NAME}:${IMAGE_TAG} .'
}
}
}
stage('Pushing to ECR') {
steps{
withDockerRegistry(credentialsId: 'ecr:eu-west-1:CICD-ECRUser', url: 'https:
script {
sh "docker tag ${IMAGE_REPO_NAME}:${IMAGE_TAG} ${REPOSITORY_URI}:$IMAGE_TAG"
sh "docker push 386288228052.dkr.ecr.eu-west-1.amazonaws.com/${IMAGE_REPO_NAME}:${IMAGE_TAG}"
sh 'echo "pushed successfulyyy"'
}
}
}
}
stage('Update Deployment File') {
steps {
script {
sh '''
BUILD_NUMBER=${BUILD_NUMBER}
ls -ltr
pwd
sed -i "s/replaceImageTag/${BUILD_NUMBER}/g" /var/lib/jenkins/workspace/UltimateCICD/java-maven-sonar-argocd-helm-k8s/spring-boot-app-manifests/deployment.yaml
git config --global user.email "kakarlayogitha@gmail.com"
git config --global user.name "yogitha"
git add java-maven-sonar-argocd-helm-k8s/spring-boot-app-manifests/deployment.yaml
git commit -m "Update deployment image to version ${BUILD_NUMBER}"
git push codecommit main
'''
}
}
}
}
}