From 2f1018a3699538a7291cd42b8830056a0abb807a Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 1 Feb 2023 23:18:41 +0000 Subject: [PATCH] environment test --- Dockerfile | 7 ++++--- Jenkinsfile | 18 ++++++------------ build.gradle | 11 +++-------- settings.gradle | 2 +- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index 280f949..cd7d9c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ FROM openjdk:11 -ARG JAR_NAME -COPY build/libs/${JAR_NAME} ${JAR_NAME} -ENTRYPOINT ["java", "-jar", "/${JAR_NAME}"] \ No newline at end of file +ARG PROJECT_NAME +ARG PROJECT_VERSION +COPY build/libs/${PROJECT_NAME}-${PROJECT_VERSION} ${PROJECT_NAME}-${PROJECT_VERSION} +ENTRYPOINT ["java", "-jar", "/${PROJECT_NAME}-${PROJECT_VERSION}"] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 3ebf5f3..f209b91 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -41,23 +41,17 @@ 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 = "harbor.loafle.net" - def app_version_value = sh(returnStdout: true, script: "cat build.gradle | grep -o 'version = [^,]*'").trim() - sh "echo Project in version value: $app_version_value" - def app_version = app_version_value.split(/=/)[1].trim() + def dockerRegistryUrl = "harbor.loafle.net" stage('Test') { try { container('gradle') { - def project_name = sh(returnStdout: true, script: "gradle -q projectName").trim() - sh "echo Project name: $project_name" - def project_version = sh(returnStdout: true, script: "gradle -q projectVersion").trim() - sh "echo Project version: $project_version" - + def projectDetails = sh(returnStdout: true, script: "gradle -q projectDetails").trim() sh """ pwd echo "GIT_BRANCH=${gitBranch}" >> /etc/environment echo "GIT_COMMIT=${gitCommit}" >> /etc/environment + echo "${projectDetails}" >> /etc/environment gradle test """ } @@ -81,9 +75,9 @@ podTemplate( 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:${app_version} --build-arg JAR_NAME=cicd-${app_version}.jar . - docker push ${docker_registry_url}/prototype/cicd-java-spring-boot:${app_version} + docker login -u "${HARBOR_USER}" -p "${HARBOR_PASSWORD}" ${dockerRegistryRrl} + docker build -t ${dockerRegistryRrl}/prototype/${PROJECT_NAME}:${PROJECT_VERSION} --build-arg PROJECT_NAME=${PROJECT_NAME} --build-arg PROJECT_VERSION=${PROJECT_VERSION} . + docker push ${dockerRegistryRrl}/prototype/${PROJECT_NAME}:${PROJECT_VERSION} """ } } diff --git a/build.gradle b/build.gradle index 15eb41d..5ce7e56 100644 --- a/build.gradle +++ b/build.gradle @@ -21,14 +21,9 @@ tasks.named('test') { useJUnitPlatform() } -task projectName { +task projectDetails { doLast { - println "${project.name}" + println "PROJECT_NAME=${project.name}" + println "PROJECT_VERSION=${project.version}" } } - -task projectVersion { - doLast { - println "${project.version}" - } -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index ac1901e..b8e43db 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'cicd' +rootProject.name = 'cicd-java-spring-boot'