diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..280f949 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM openjdk:11 +ARG JAR_NAME +COPY build/libs/${JAR_NAME} ${JAR_NAME} +ENTRYPOINT ["java", "-jar", "/${JAR_NAME}"] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 2cb678a..0592a55 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -40,6 +40,7 @@ podTemplate( def gitBranch = myRepo.GIT_BRANCH def shortGitCommit = "${gitCommit[0..10]}" def previousGitCommit = sh(script: "git rev-parse ${gitCommit}~", returnStdout: true) + def docker_registry_url = "harboar.loafle.net" stage('Test') { try { @@ -57,11 +58,26 @@ podTemplate( throw(exc) } } + stage('Build') { container('gradle') { sh "gradle build" } } + stage('Create Docker images') { + container('docker') { + withCredentials([[$class: 'UsernamePasswordMultiBinding', + credentialsId: 'harbor.loafle.net', + usernameVariable: 'HARBOR_USER', + passwordVariable: 'HARBOR_PASSWORD']]) { + sh """ + docker login -u ${HARBOR_USER} -p ${HARBOR_PASSWORD} ${docker_registry_url} + docker build -t ${docker_registry_url}/prototype/cicd-java-spring-boot:${gitCommit} -f Dockerfile.arg --build-arg JAR_NAME="cicd-${gitCommit}.jar" . + docker push ${docker_registry_url}/prototype/cicd-java-spring-boot:${gitCommit} + """ + } + } + } } }