diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..96f9269 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM adoptopenjdk/openjdk11:alpine-jre + +ARG artifact=target/spring-boot-multi.jar + +WORKDIR /app + +COPY ${artifact} app.jar + +ENTRYPOINT ["java","-jar","app.jar"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..9daec4d --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,47 @@ +pipeline { + agent { + docker { + image 'abhishekf5/maven-abhishek-docker-agent:v1' + args '--user root -v /var/run/docker.sock:/var/run/docker.sock' + } + } + stages { + stage('Checkout') { + steps { + git branch: 'main', url: 'https://github.com/prashanths-07/spring-boot-multibranch.git' + } + } + stage('Build and Test') { + steps { + sh 'ls -ltr' + sh 'cd spring-boot-multibranch && mvn clean package' + } + } + stage('Static Code Analysis') { + environment { + SONAR_URL = "http://:9000" + } + steps { + withCredentials([string(credentialsId: 'sonarqube', variable: 'SONAR_AUTH_TOKEN')]) { + sh 'cd spring-boot-multibranch && mvn sonar:sonar -Dsonar.login=$SONAR_AUTH_TOKEN -Dsonar.host.url=${SONAR_URL}' + } + } + } + stage('Build and Push Docker Image') { + environment { + DOCKER_IMAGE = "sprs16/multibranch-ci:${BUILD_NUMBER}" + DOCKERFILE_LOCATION = "spring-boot-multibranch/Dockerfile" + REGISTRY_CREDENTIALS = credentials('docker-cred') + } + steps { + script { + sh 'cd spring-boot-multibranch && docker build -t ${DOCKER_IMAGE} .' + def dockerImage = docker.image("${DOCKER_IMAGE}") + docker.withRegistry('https://index.docker.io/v1/', "docker-cred") { + dockerImage.push() + } + } + } + } + } +}