Skip to content
Snippets Groups Projects
Commit 5d6e65dc authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4561 OZG-4565 adjust Jenkinsfile

parent e46d18b9
Branches
Tags
No related merge requests found
...@@ -6,7 +6,7 @@ pipeline { ...@@ -6,7 +6,7 @@ pipeline {
} }
environment { environment {
BLUE_OCEAN_URL = "https://jenkins.infra.ozg-cloud.systems/job/goofy/job/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/" BLUE_OCEAN_URL = "https://jenkins.infra.ozg-cloud.systems/job/alfa/job/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/"
RELEASE_REGEX = /\d+.\d+.\d+/ RELEASE_REGEX = /\d+.\d+.\d+/
SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/ SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/
FAILED_STAGE = "" FAILED_STAGE = ""
...@@ -25,8 +25,8 @@ pipeline { ...@@ -25,8 +25,8 @@ pipeline {
script { script {
FAILED_STAGE = env.STAGE_NAME FAILED_STAGE = env.STAGE_NAME
VERSION = getRootPomVersion() VERSION = getRootPomVersion()
def serverVersion = getParentPomVersion('goofy-server/pom.xml') def serverVersion = getParentPomVersion('alfa-server/pom.xml')
def clientVersion = getParentPomVersion('goofy-client/pom.xml') def clientVersion = getParentPomVersion('alfa-client/pom.xml')
if(isReleaseBranch()){ if(isReleaseBranch()){
if ( !isReleaseVersion([VERSION, serverVersion, clientVersion]) ) { if ( !isReleaseVersion([VERSION, serverVersion, clientVersion]) ) {
...@@ -51,7 +51,7 @@ pipeline { ...@@ -51,7 +51,7 @@ pipeline {
sh 'npm --version' sh 'npm --version'
sh 'node --version' sh 'node --version'
dir('goofy-client') { dir('alfa-client') {
sh 'echo "registry=https://nexus.ozg-sh.de/repository/npm-proxy" >> ~/.npmrc' sh 'echo "registry=https://nexus.ozg-sh.de/repository/npm-proxy" >> ~/.npmrc'
sh 'echo "//nexus.ozg-sh.de/:_auth=amVua2luczprTSFnNVUhMVQzNDZxWQ==" >> ~/.npmrc' sh 'echo "//nexus.ozg-sh.de/:_auth=amVua2luczprTSFnNVUhMVQzNDZxWQ==" >> ~/.npmrc'
...@@ -81,7 +81,7 @@ pipeline { ...@@ -81,7 +81,7 @@ pipeline {
} }
// post { // post {
// always{ // always{
// junit testResults: 'goofy-client/test-report.xml', skipPublishingChecks: true // junit testResults: 'alfa-client/test-report.xml', skipPublishingChecks: true
// } // }
// } // }
} }
...@@ -93,7 +93,7 @@ pipeline { ...@@ -93,7 +93,7 @@ pipeline {
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn --version' sh 'mvn --version'
sh "mvn -s $MAVEN_SETTINGS -pl -goofy-client clean install spring-boot:build-image -Dspring-boot.build-image.imageName=docker.ozg-sh.de/goofy:${IMAGE_TAG} -Dspring-boot.build-image.publish -Dmaven.wagon.http.retryHandler.count=3" sh "mvn -s $MAVEN_SETTINGS -pl -alfa-client clean install spring-boot:build-image -Dspring-boot.build-image.imageName=docker.ozg-sh.de/alfa:${IMAGE_TAG} -Dspring-boot.build-image.publish -Dmaven.wagon.http.retryHandler.count=3"
if (isMasterBranch()) { if (isMasterBranch()) {
try { try {
...@@ -134,7 +134,7 @@ pipeline { ...@@ -134,7 +134,7 @@ pipeline {
} }
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn -s $MAVEN_SETTINGS -pl -goofy-client -DskipTests deploy' sh 'mvn -s $MAVEN_SETTINGS -pl -alfa-client -DskipTests deploy'
} }
} }
} }
...@@ -145,7 +145,6 @@ pipeline { ...@@ -145,7 +145,6 @@ pipeline {
branch 'release' branch 'release'
} }
} }
steps { steps {
script { script {
FAILED_STAGE = env.STAGE_NAME FAILED_STAGE = env.STAGE_NAME
...@@ -163,7 +162,7 @@ pipeline { ...@@ -163,7 +162,7 @@ pipeline {
stage('Test, build and deploy Helm Chart') { stage('Test, build and deploy Helm Chart') {
steps { steps {
script { script {
FAILED_GOOFY_STAGE=env.STAGE_NAME FAILED_STAGE=env.STAGE_NAME
HELM_CHART_VERSION = generateHelmChartVersion() HELM_CHART_VERSION = generateHelmChartVersion()
dir('src/main/helm') { dir('src/main/helm') {
...@@ -189,7 +188,7 @@ pipeline { ...@@ -189,7 +188,7 @@ pipeline {
cloneGitopsRepo() cloneGitopsRepo()
setNewDevGoofyVersion() setNewDevVersion()
pushGitopsRepo() pushGitopsRepo()
} }
} }
...@@ -200,14 +199,13 @@ pipeline { ...@@ -200,14 +199,13 @@ pipeline {
when { when {
branch 'release' branch 'release'
} }
steps { steps {
script { script {
FAILED_STAGE = env.STAGE_NAME FAILED_STAGE = env.STAGE_NAME
cloneGitopsRepo() cloneGitopsRepo()
setNewTestGoofyVersion() setNewTestVersion()
pushGitopsRepo() pushGitopsRepo()
} }
} }
...@@ -244,10 +242,10 @@ pipeline { ...@@ -244,10 +242,10 @@ pipeline {
Void deployHelmChart(String helmChartVersion) { Void deployHelmChart(String helmChartVersion) {
withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]){ withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]){
if (isReleaseBranch()) { if (isReleaseBranch()) {
result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps -F file=@goofy-'''+helmChartVersion+'''.tgz''', returnStdout: true result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps -F file=@alfa-'''+helmChartVersion+'''.tgz''', returnStdout: true
} }
else { else {
result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps-snapshot -F file=@goofy-'''+helmChartVersion+'''.tgz''', returnStdout: true result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps-snapshot -F file=@alfa-'''+helmChartVersion+'''.tgz''', returnStdout: true
} }
if (result != '') { if (result != '') {
...@@ -273,8 +271,8 @@ Void tagAndPushDockerImage(String newTag){ ...@@ -273,8 +271,8 @@ Void tagAndPushDockerImage(String newTag){
withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) { withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) {
sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}' sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}'
sh "docker tag docker.ozg-sh.de/goofy:${IMAGE_TAG} docker.ozg-sh.de/goofy:${newTag}" sh "docker tag docker.ozg-sh.de/alfa:${IMAGE_TAG} docker.ozg-sh.de/alfa:${newTag}"
sh "docker push docker.ozg-sh.de/goofy:${newTag}" sh "docker push docker.ozg-sh.de/alfa:${newTag}"
} }
} }
...@@ -322,9 +320,9 @@ Void configureGit() { ...@@ -322,9 +320,9 @@ Void configureGit() {
Void sendFailureMessage() { Void sendFailureMessage() {
def room = '' def room = ''
def data = """{"msgtype":"m.text", \ def data = """{"msgtype":"m.text", \
"body":"Goofy: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER} Link: ${BLUE_OCEAN_URL}", \ "body":"Alfa: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER} Link: ${BLUE_OCEAN_URL}", \
"format": "org.matrix.custom.html", \ "format": "org.matrix.custom.html", \
"formatted_body":"Goofy: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}""" "formatted_body":"Alfa: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}"""
if (isMasterBranch()) { if (isMasterBranch()) {
room = "!iQPAvQIiRwRpNOszjw:matrix.ozg-sh.de" room = "!iQPAvQIiRwRpNOszjw:matrix.ozg-sh.de"
...@@ -342,34 +340,34 @@ String getElementAccessToken() { ...@@ -342,34 +340,34 @@ String getElementAccessToken() {
} }
} }
Void setNewDevGoofyVersion() { Void setNewDevVersion() {
setNewGoofyGitopsVersion("dev") setNewGitopsVersion("dev")
} }
Void setNewTestGoofyVersion() { Void setNewTestVersion() {
setNewGoofyGitopsVersion("test") setNewGitopsVersion("test")
} }
Void setNewGoofyGitopsVersion(String environment) { Void setNewGitopsVersion(String environment) {
dir("gitops") { dir("gitops") {
def envFile = "${environment}/application/values/goofy-values.yaml" def envFile = "${environment}/application/values/alfa-values.yaml"
def envVersions = readYaml file: envFile def envVersions = readYaml file: envFile
envVersions.goofy.image.tag = IMAGE_TAG envVersions.alfa.image.tag = IMAGE_TAG
envVersions.goofy.helm.version = HELM_CHART_VERSION envVersions.alfa.helm.version = HELM_CHART_VERSION
writeYaml file: envFile, data: envVersions, overwrite: true writeYaml file: envFile, data: envVersions, overwrite: true
if (hasGoofyValuesFileChanged(environment)) { if (hasValuesFileChanged(environment)) {
sh "git add ${envFile}" sh "git add ${envFile}"
sh "git commit -m 'jenkins rollout ${environment} goofy version ${IMAGE_TAG}'" sh "git commit -m 'jenkins rollout ${environment} alfa version ${IMAGE_TAG}'"
} }
} }
} }
Boolean hasGoofyValuesFileChanged(String environment) { Boolean hasValuesFileChanged(String environment) {
return sh (script: "git status | grep '${environment}/application/values/goofy-values.yaml'", returnStatus: true) == env.SH_SUCCESS_STATUS_CODE as Integer return sh (script: "git status | grep '${environment}/application/values/alfa-values.yaml'", returnStatus: true) == env.SH_SUCCESS_STATUS_CODE as Integer
} }
Boolean isReleaseBranch() { Boolean isReleaseBranch() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment