environment test

This commit is contained in:
crusader 2023-02-01 23:18:41 +00:00
parent ed75f77457
commit 2f1018a369
4 changed files with 14 additions and 24 deletions

View File

@ -1,4 +1,5 @@
FROM openjdk:11
ARG JAR_NAME
COPY build/libs/${JAR_NAME} ${JAR_NAME}
ENTRYPOINT ["java", "-jar", "/${JAR_NAME}"]
ARG PROJECT_NAME
ARG PROJECT_VERSION
COPY build/libs/${PROJECT_NAME}-${PROJECT_VERSION} ${PROJECT_NAME}-${PROJECT_VERSION}
ENTRYPOINT ["java", "-jar", "/${PROJECT_NAME}-${PROJECT_VERSION}"]

18
Jenkinsfile vendored
View File

@ -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}
"""
}
}

View File

@ -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}"
}
}

View File

@ -1 +1 @@
rootProject.name = 'cicd'
rootProject.name = 'cicd-java-spring-boot'