diff --git a/Jenkinsfile b/Jenkinsfile index 5ff0de1856887fab6edf8341ec5ec333b5aeeda1..53861d6861aef7b56661aefe6ee7a783a919fd90 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,6 +12,7 @@ pipeline { SH_SUCCESS_STATUS_CODE = 0 IMAGE_TAG = generateImageTag() HELM_CHART_VERSION = generateHelmChartVersion() + BUILD_PROFILE = getBuildProfile() } options { @@ -77,7 +78,7 @@ pipeline { configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) { - sh 'mvn -s $MAVEN_SETTINGS spring-boot:build-image -DskipTests -Dmaven.wagon.http.retryHandler.count=3 -Dbuildtag=$IMAGE_TAG -Dspring-boot.build-image.publish=true -Duser=${USER} -Dpassword=${PASSWORD}' + sh 'mvn -s $MAVEN_SETTINGS spring-boot:build-image -DskipTests -Dmaven.wagon.http.retryHandler.count=3 $BUILD_PROFILE -Ddocker.publishRegistry.username=${USER} -Ddocker.publishRegistry.password=${PASSWORD}' } } } @@ -154,13 +155,6 @@ pipeline { } String generateImageTag() { - - if (isMasterBranch()) { - return "snapshot-latest" - } - else if (isReleaseBranch()) { - return "latest" - } return "${env.BRANCH_NAME}-${getPomVersion()}" } @@ -170,6 +164,16 @@ String getPomVersion() { return pom.version } +String getBuildProfile() { + if (isMasterBranch()) { + return "-P dev" + } else if (isReleaseBranch()) { + return "-P release" + } else { + return "" + } +} + Void sendFailureMessage() { def room = getRoom() diff --git a/pom.xml b/pom.xml index 98d982086c13a4605a42a2f4cbee9958b6a52707..d8bbbd530973ea0721fd0309acc512bfeae8c62f 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,7 @@ <description>Administration Backend Project</description> <properties> + <imageName>docker.ozg-sh.de/administration</imageName> <build.number>SET_BY_JENKINS</build.number> </properties> @@ -54,29 +55,66 @@ <scope>test</scope> </dependency> </dependencies> - + <profiles> + <profile> + <id>dev</id> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <image> + <tags>${imageName}:snapshot-latest</tags> + </image> + </configuration> + </plugin> + </plugins> + </build> + </profile> + <profile> + <id>release</id> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <image> + <tags>${imageName}:latest</tags> + </image> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> <build> <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <image> - <name>docker.ozg-sh.de/administration:${buildtag}</name> + <name>${imageName}:${env.BRANCH_NAME}-${project.version}</name> <publish>true</publish> </image> <docker> <publishRegistry> - <username>${user}</username> - <password>${password}</password> + <username>${docker.publishRegistry.username}</username> + <password>${docker.publishRegistry.password}</password> </publishRegistry> - </docker> - <excludes> - <exclude> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - </exclude> - </excludes> + </docker> + <excludes> + <exclude> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + </exclude> + </excludes> </configuration> <executions> <execution>