Skip to content
Snippets Groups Projects
Commit 979522b6 authored by Stefan Hauffe's avatar Stefan Hauffe
Browse files

OZG-7324: Update Jenkinsfiles to only contain frontend.

parent b04847f9
Branches
Tags
No related merge requests found
...@@ -29,7 +29,7 @@ pipeline { ...@@ -29,7 +29,7 @@ pipeline {
} }
environment { environment {
BLUE_OCEAN_URL = "https://jenkins.infra.ozg-cloud.systems/job/alfa/job/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/" BLUE_OCEAN_URL = "https://jenkins.infra.ozg-cloud.systems/job/codeSH_frontendclients/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 = ""
...@@ -50,23 +50,17 @@ pipeline { ...@@ -50,23 +50,17 @@ pipeline {
steps { steps {
script { script {
FAILED_STAGE = env.STAGE_NAME FAILED_STAGE = env.STAGE_NAME
VERSION = getRootPomVersion() VERSION = getAlfaPackageJsonVersion()
def serverVersion = getParentPomVersion('alfa-server/pom.xml')
def clientVersion = getParentPomVersion('alfa-client/pom.xml')
if(isReleaseBranch()){ if(isReleaseBranch()){
if ( !isReleaseVersion([VERSION, serverVersion, clientVersion]) ) { if ( !isReleaseVersion([VERSION]) ) {
error("Keine Release Version für Branch ${env.BRANCH_NAME}.") error("Keine Release Version für Branch ${env.BRANCH_NAME}.")
} }
} else { } else {
if ( !isSnapshotVersion([VERSION, serverVersion, clientVersion]) ) { if ( !isSnapshotVersion([VERSION]) ) {
error("Keine Snapshot Version für Branch ${env.BRANCH_NAME}.") error("Keine Snapshot Version für Branch ${env.BRANCH_NAME}.")
} }
} }
if( !isSameVersion([serverVersion, clientVersion], VERSION) ){
error("Versionen sind nicht identisch")
}
} }
} }
} }
...@@ -87,7 +81,7 @@ pipeline { ...@@ -87,7 +81,7 @@ pipeline {
sh 'npm cache verify' sh 'npm cache verify'
sh 'npm install' sh 'npm install'
if (isMasterBranch()) { if (isMainBranch()) {
withSonarQubeEnv('sonarqube-ozg-sh'){ withSonarQubeEnv('sonarqube-ozg-sh'){
sh 'npm run ci-sonar' sh 'npm run ci-sonar'
} }
...@@ -122,87 +116,17 @@ pipeline { ...@@ -122,87 +116,17 @@ pipeline {
sh 'npm run ci-build-alfa-client-container' sh 'npm run ci-build-alfa-client-container'
} }
withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) { tagAndPushDockerImage('build-latest', IMAGE_TAG)
sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}'
sh "docker tag docker.ozg-sh.de/alfa-client:build-latest docker.ozg-sh.de/alfa-client:${IMAGE_TAG}"
sh "docker push docker.ozg-sh.de/alfa-client:${IMAGE_TAG}"
}
}
}
}
}
}
stage('Set Version') {
when {
not {
anyOf {
branch 'master'
branch 'release'
}
}
}
steps {
script {
FAILED_STAGE=env.STAGE_NAME
JAR_TAG = getRootPomVersion().replace("SNAPSHOT", "${env.BRANCH_NAME}-SNAPSHOT")
}
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh "mvn -s $MAVEN_SETTINGS versions:set -DnewVersion=${JAR_TAG} -DprocessAllModules=true"
}
}
}
stage('Build Server artefacts, build and push docker image') {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
IMAGE_TAG = buildVersionName()
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn --version'
sh "mvn -s $MAVEN_SETTINGS -pl -alfa-client clean install"
sh "mvn --no-transfer-progress -s $MAVEN_SETTINGS -pl -alfa-client 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()) {
try {
dir('alfa-service'){
withSonarQubeEnv('sonarqube-ozg-sh'){
sh 'mvn --no-transfer-progress -s $MAVEN_SETTINGS sonar:sonar'
}
}
}
catch (Exception e) {
unstable("SonarQube failed")
}
}
} }
} }
} }
post {
always{
junit testResults: '**/target/surefire-reports/*.xml', skipPublishingChecks: true
}
} }
} }
stage('Deploy Maven Artifacts to Nexus') {
steps {
script {
FAILED_STAGE = env.STAGE_NAME
}
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn --no-transfer-progress -s $MAVEN_SETTINGS -pl -alfa-client -DskipTests deploy'
sh "mvn -s $MAVEN_SETTINGS versions:revert"
}
}
}
stage('Tag and Push Docker Image') { stage('Tag and Push Docker Image') {
when { when {
anyOf { anyOf {
branch 'master' branch 'main'
branch 'release' branch 'release'
} }
} }
...@@ -211,29 +135,11 @@ pipeline { ...@@ -211,29 +135,11 @@ pipeline {
script { script {
FAILED_STAGE = env.STAGE_NAME FAILED_STAGE = env.STAGE_NAME
if (isMasterBranch()) { if (isMainBranch()) {
tagAndPushDockerImage('snapshot-latest') tagAndPushDockerImage(IMAGE_TAG, 'snapshot-latest')
} }
else if (isReleaseBranch()) { else if (isReleaseBranch()) {
tagAndPushDockerImage('latest') tagAndPushDockerImage(IMAGE_TAG, 'latest')
}
}
}
}
stage('Test, build and deploy Alfa Helm Chart') {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
HELM_CHART_VERSION = buildVersionName()
sh "./run_helm_test.sh"
dir('src/main/helm') {
sh "helm package --version=${HELM_CHART_VERSION} ."
deployHelmChart(HELM_CHART_VERSION, "alfa")
} }
} }
} }
...@@ -261,7 +167,7 @@ pipeline { ...@@ -261,7 +167,7 @@ pipeline {
stage('Trigger Dev rollout') { stage('Trigger Dev rollout') {
when { when {
branch 'master' branch 'main'
} }
steps { steps {
script { script {
...@@ -275,7 +181,6 @@ pipeline { ...@@ -275,7 +181,6 @@ pipeline {
} }
} }
stage('Trigger Test rollout') { stage('Trigger Test rollout') {
when { when {
branch 'release' branch 'release'
...@@ -292,25 +197,6 @@ pipeline { ...@@ -292,25 +197,6 @@ pipeline {
} }
} }
stage ('Deploy SBOM to DependencyTrack') {
steps {
script {
IMAGE_TAG = buildVersionName()
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
withCredentials([string(credentialsId: 'dependency-track-api-key', variable: 'API_KEY')]) {
dir('alfa-server') {
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
sh "mvn --no-transfer-progress -s $MAVEN_SETTINGS io.github.pmckeown:dependency-track-maven-plugin:upload-bom -Ddependency-track.apiKey=$API_KEY -Ddependency-track.projectVersion=${IMAGE_TAG} -Ddependency-track.dependencyTrackBaseUrl=https://dependency-track.ozg-sh.de"
}
}
}
}
}
}
}
stage ('Trigger Barrierefreiheit Rollout') { stage ('Trigger Barrierefreiheit Rollout') {
when { when {
branch 'barrierefreiheit-dev' branch 'barrierefreiheit-dev'
...@@ -333,7 +219,7 @@ pipeline { ...@@ -333,7 +219,7 @@ pipeline {
post { post {
failure { failure {
script { script {
if (isMasterBranch() || isReleaseBranch()) { if (isMainBranch() || isReleaseBranch()) {
sendFailureMessage() sendFailureMessage()
} }
} }
...@@ -370,21 +256,21 @@ String validateBranchName(branchName) { ...@@ -370,21 +256,21 @@ String validateBranchName(branchName) {
String buildVersionName() { String buildVersionName() {
if (isReleaseBranch()) { if (isReleaseBranch()) {
return getRootPomVersion() return VERSION
} }
if (isBarrierefreiheitBranch()) { if (isBarrierefreiheitBranch()) {
return "${getRootPomVersion()}-barrierefreiheit${validateBranchName(env.BRANCH_NAME)}${getCommitHash()}".replaceAll("_", "-") return "${VERSION}-barrierefreiheit${validateBranchName(env.BRANCH_NAME)}${getCommitHash()}".replaceAll("_", "-")
} }
return "${getRootPomVersion()}-${validateBranchName(env.BRANCH_NAME)}${getCommitHash()}".replaceAll("_", "-") return "${VERSION}-${validateBranchName(env.BRANCH_NAME)}${getCommitHash()}".replaceAll("_", "-")
} }
Void tagAndPushDockerImage(String newTag){ Void tagAndPushDockerImage(String currentTag, 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/alfa:${IMAGE_TAG} docker.ozg-sh.de/alfa:${newTag}" sh "docker tag docker.ozg-sh.de/alfa-client:${currentTag} docker.ozg-sh.de/alfa-client:${newTag}"
sh "docker push docker.ozg-sh.de/alfa:${newTag}" sh "docker push docker.ozg-sh.de/alfa-client:${newTag}"
} }
} }
...@@ -422,11 +308,11 @@ Void configureGit() { ...@@ -422,11 +308,11 @@ Void configureGit() {
Void sendFailureMessage() { Void sendFailureMessage() {
def room = '' def room = ''
def data = """{"msgtype":"m.text", \ def data = """{"msgtype":"m.text", \
"body":"Alfa: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER} Link: ${BLUE_OCEAN_URL}", \ "body":"Alfa-Client: 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":"Alfa: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}""" "formatted_body":"Alfa-Client: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}"""
if (isMasterBranch()) { if (isMainBranch()) {
room = "!iQPAvQIiRwRpNOszjw:matrix.ozg-sh.de" room = "!iQPAvQIiRwRpNOszjw:matrix.ozg-sh.de"
} }
else if (isReleaseBranch()) { else if (isReleaseBranch()) {
...@@ -452,10 +338,6 @@ Void setNewTestVersion() { ...@@ -452,10 +338,6 @@ Void setNewTestVersion() {
} }
Void setNewGitopsVersion(String environment) { Void setNewGitopsVersion(String environment) {
def envFile = "${environment}/application/values/alfa-values.yaml"
def commitMessage = "jenkins rollout ${environment} alfa version ${IMAGE_TAG}";
setNewAlfaGitopsVersion(envFile, commitMessage);
envFile = "${environment}/application/values/alfa-client-values.yaml" envFile = "${environment}/application/values/alfa-client-values.yaml"
commitMessage = "jenkins rollout ${environment} alfa-client version ${IMAGE_TAG}"; commitMessage = "jenkins rollout ${environment} alfa-client version ${IMAGE_TAG}";
setNewAlfaClientGitopsVersion(envFile, commitMessage); setNewAlfaClientGitopsVersion(envFile, commitMessage);
...@@ -464,23 +346,7 @@ Void setNewGitopsVersion(String environment) { ...@@ -464,23 +346,7 @@ Void setNewGitopsVersion(String environment) {
Void setNewBarrierefreiheitVersion() { Void setNewBarrierefreiheitVersion() {
def envFile = "dev/namespace/namespaces/by-barrierefreiheit-dev.yaml" def envFile = "dev/namespace/namespaces/by-barrierefreiheit-dev.yaml"
def commitMessage = "jenkins rollout ${IMAGE_TAG} for Barrierefreiheit Dev" def commitMessage = "jenkins rollout ${IMAGE_TAG} for Barrierefreiheit Dev"
setNewAlfaGitopsVersion(envFile, commitMessage); setNewAlfaClientGitopsVersion(envFile, commitMessage);
}
Void setNewAlfaGitopsVersion(String envFile, String commitMessage) {
dir("gitops") {
def envVersions = readYaml file: envFile
envVersions.alfa.image.tag = IMAGE_TAG
envVersions.alfa.helm.version = HELM_CHART_VERSION
writeYaml file: envFile, data: envVersions, overwrite: true
if (hasValuesFileChanged(envFile)) {
sh "git add ${envFile}"
sh "git commit -m '${commitMessage}'"
}
}
} }
Void setNewAlfaClientGitopsVersion(String envFile, String commitMessage) { Void setNewAlfaClientGitopsVersion(String envFile, String commitMessage) {
...@@ -511,8 +377,8 @@ Boolean isReleaseBranch() { ...@@ -511,8 +377,8 @@ Boolean isReleaseBranch() {
return env.BRANCH_NAME == 'release' return env.BRANCH_NAME == 'release'
} }
Boolean isMasterBranch() { Boolean isMainBranch() {
return env.BRANCH_NAME == 'master' return env.BRANCH_NAME == 'main'
} }
Boolean isBarrierefreiheitBranch() { Boolean isBarrierefreiheitBranch() {
...@@ -538,22 +404,9 @@ Boolean matchRegexVersion(List versions, String regex) { ...@@ -538,22 +404,9 @@ Boolean matchRegexVersion(List versions, String regex) {
return true return true
} }
Boolean isSameVersion(List versions, String expectedVersion) { String getAlfaPackageJsonVersion() {
for (version in versions) { def packageJSON = readJSON file: 'alfa-client/apps/alfa/package.json'
if ( version != expectedVersion ) { def packageJSONVersion = packageJSON.version
return false echo packageJSONVersion
} return packageJSONVersion
}
return true
}
String getRootPomVersion() {
def rootPom = readMavenPom file: 'pom.xml'
return rootPom.version
}
String getParentPomVersion(String filePath) {
def pom = readMavenPom file: filePath
return pom.parent.version
} }
\ No newline at end of file
...@@ -50,14 +50,22 @@ pipeline { ...@@ -50,14 +50,22 @@ pipeline {
steps { steps {
script { script {
FAILED_STAGE = env.STAGE_NAME FAILED_STAGE = env.STAGE_NAME
dir('alfa-client') { VERSION = getAdminPackageJsonVersion()
VERSION = getPackagejsonVersion()
if(isReleaseBranch()){
if ( !isReleaseVersion([VERSION]) ) {
error("Keine Release Version für Branch ${env.BRANCH_NAME}.")
}
} else {
if ( !isSnapshotVersion([VERSION]) ) {
error("Keine Snapshot Version für Branch ${env.BRANCH_NAME}.")
}
} }
} }
} }
} }
stage('build admin client and its docker image') { stage('Build admin client and its docker image') {
steps { steps {
script { script {
FAILED_STAGE=env.STAGE_NAME FAILED_STAGE=env.STAGE_NAME
...@@ -72,7 +80,7 @@ pipeline { ...@@ -72,7 +80,7 @@ pipeline {
} else { } else {
sh 'npm run ci-build-admin' sh 'npm run ci-build-admin'
} }
if (isMasterBranch()) { if (isMainBranch()) {
withSonarQubeEnv('sonarqube-ozg-sh'){ withSonarQubeEnv('sonarqube-ozg-sh'){
sh 'npm run ci-sonar' sh 'npm run ci-sonar'
} }
...@@ -93,7 +101,7 @@ pipeline { ...@@ -93,7 +101,7 @@ pipeline {
tagAndPushDockerImage(IMAGE_TAG) tagAndPushDockerImage(IMAGE_TAG)
if (isMasterBranch()) { if (isMainBranch()) {
tagAndPushDockerImage('snapshot-latest') tagAndPushDockerImage('snapshot-latest')
} }
else if (isReleaseBranch()) { else if (isReleaseBranch()) {
...@@ -125,7 +133,7 @@ pipeline { ...@@ -125,7 +133,7 @@ pipeline {
stage('Trigger Dev rollout') { stage('Trigger Dev rollout') {
when { when {
branch 'master' branch 'main'
} }
steps { steps {
script { script {
...@@ -159,7 +167,7 @@ pipeline { ...@@ -159,7 +167,7 @@ pipeline {
post { post {
failure { failure {
script { script {
if (isMasterBranch() || isReleaseBranch()) { if (isMainBranch() || isReleaseBranch()) {
sendFailureMessage() sendFailureMessage()
} }
} }
...@@ -260,8 +268,8 @@ Void tagAndPushDockerImage(String newTag){ ...@@ -260,8 +268,8 @@ Void tagAndPushDockerImage(String newTag){
sh "docker push docker.ozg-sh.de/admin-client:${newTag}" sh "docker push docker.ozg-sh.de/admin-client:${newTag}"
} }
} }
String getPackagejsonVersion() { String getAdminPackageJsonVersion() {
def packageJSON = readJSON file: 'package.json' def packageJSON = readJSON file: 'alfa-client/apps/admin/package.json'
def packageJSONVersion = packageJSON.version def packageJSONVersion = packageJSON.version
echo packageJSONVersion echo packageJSONVersion
return packageJSONVersion return packageJSONVersion
...@@ -282,8 +290,8 @@ Void deployHelmChart(String helmChartVersion) { ...@@ -282,8 +290,8 @@ Void deployHelmChart(String helmChartVersion) {
} }
} }
Boolean isMasterBranch() { Boolean isMainBranch() {
return env.BRANCH_NAME == 'master' return env.BRANCH_NAME == 'main'
} }
Void sendFailureMessage() { Void sendFailureMessage() {
...@@ -293,7 +301,7 @@ Void sendFailureMessage() { ...@@ -293,7 +301,7 @@ Void sendFailureMessage() {
"format": "org.matrix.custom.html", \ "format": "org.matrix.custom.html", \
"formatted_body":"Admin-Client: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}""" "formatted_body":"Admin-Client: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}"""
if (isMasterBranch()) { if (isMainBranch()) {
room = "!iQPAvQIiRwRpNOszjw:matrix.ozg-sh.de" room = "!iQPAvQIiRwRpNOszjw:matrix.ozg-sh.de"
} }
else if (isReleaseBranch()) { else if (isReleaseBranch()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment