diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..e0e20cf3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM openjdk:jdk + +RUN mkdir /app + +COPY ./target/sample-0.0.1-SNAPSHOT.jar /app + +WORKDIR /app + +CMD ("java" "-jar" "./target/sample-0.0.1-SNAPSHOT.jar") \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..5b9ea1fc --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,57 @@ +def gv + +pipeline{ + +agent any + +tools{ + maven 'maven-3.8.6' +} + +stages{ + stage("groovy file call"){ + steps{ + script{ + gv = load "script.groovy" + } + } + } + stage("build jar file"){ + steps{ + script{ + gv.buildJar() + } + } + } + + stage("build image"){ + steps{ + script{ + gv.buildImage() + } + } + } + + stage("docker hub login"){ + steps{ + script{ + gv.dockerlogin() + } + } + } + + stage("push image to Dockerhub"){ + steps{ + script{ + gv.pushimage() + } + } + } + + stage("success"){ + steps{ + echo 'success' + } + } +} +} \ No newline at end of file diff --git a/script.groovy b/script.groovy new file mode 100644 index 00000000..9719580a --- /dev/null +++ b/script.groovy @@ -0,0 +1,19 @@ +def buildJar() { + sh 'mvn package' +} + +def buildImage() { + sh 'docker build -t carellevbt/test-1:sample2 .' +} + +def dockerlogin() { + withCredentials([usernamePassword(credentialsId: '7ea3ae58-0b89-46de-ba6b-085cd3c7465c', passwordVariable: 'PASS', usernameVariable: 'USER')]) { + sh 'echo $PASS | docker login -u $USER --password-stdin' + } +} + +def pushimage() { + sh 'docker push carellevbt/test-1:sample2' +} + +return this \ No newline at end of file