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

OZG-7021 OZG-7217 Prettier Jenkinsfile

parent aa99410d
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@
"embeddedLanguageFormatting": "auto",
"plugins": [
"prettier-plugin-organize-imports",
"prettier-plugin-groovy",
"prettier-plugin-tailwindcss"
],
"tailwindConfig": "./libs/design-system/src/lib/tailwind-preset/tailwind.config.js"
......
......@@ -4,7 +4,6 @@ pipeline {
label 'ozgcloud-jenkins-build-agent-jdk21-node20'
}
}
environment {
BLUE_OCEAN_URL = "https://jenkins.infra.ozg-cloud.systems/job/info/job/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/"
RELEASE_REGEX = /\d+.\d+.\d+/
......@@ -12,13 +11,11 @@ pipeline {
FAILED_STAGE = ""
SH_SUCCESS_STATUS_CODE = 0
}
options {
timeout(time: 1, unit: 'HOURS')
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '5'))
}
stages {
stage('Check Version') {
steps {
......@@ -30,41 +27,33 @@ pipeline {
}
}
}
stage('build info client and its docker image') {
steps {
script {
FAILED_STAGE = env.STAGE_NAME
dir('alfa-client') {
sh 'echo "registry=https://nexus.ozg-sh.de/repository/npm-proxy" >> ~/.npmrc'
sh 'echo "//nexus.ozg-sh.de/:_auth=amVua2luczprTSFnNVUhMVQzNDZxWQ==" >> ~/.npmrc'
sh 'npm cache verify'
sh 'npm install'
sh 'npm run ci-build-info-by'
// if (isMasterBranch()) {
// withSonarQubeEnv('sonarqube-ozg-sh'){
// sh 'npm run ci-sonar'
// }
// } else {
// sh 'npm run ci-test'
// }
if (isMasterBranch()) {
withSonarQubeEnv('sonarqube-ozg-sh') {
sh 'npm run ci-sonar'
}
} else {
sh 'npm run ci-test'
}
}
}
}
}
// stage('Tag and Push Docker image') {
// steps {
// script {
// FAILED_STAGE=env.STAGE_NAME
// IMAGE_TAG = generateImageTag()
// tagAndPushDockerImage(IMAGE_TAG)
// if (isMasterBranch()) {
// tagAndPushDockerImage('snapshot-latest')
// }
......@@ -74,27 +63,21 @@ pipeline {
// }
// }
// }
// stage('Test, build and deploy Helm Chart') {
// steps {
// script {
// FAILED_STAGE=env.STAGE_NAME
// HELM_CHART_VERSION = generateHelmChartVersion()
// dir('alfa-client/apps/admin') {
// sh "./run_helm_test.sh"
// }
// dir('alfa-client/apps/admin/src/main/helm') {
// sh "helm package --version=${HELM_CHART_VERSION} ."
// deployHelmChart(HELM_CHART_VERSION)
// }
// }
// }
// }
// stage('Trigger Dev rollout') {
// when {
// branch 'master'
......@@ -102,15 +85,12 @@ pipeline {
// steps {
// script {
// FAILED_STAGE = env.STAGE_NAME
// cloneGitopsRepo()
// setNewDevVersion()
// pushGitopsRepo()
// }
// }
// }
// stage('Trigger Test rollout') {
// when {
// branch 'release-admin'
......@@ -118,16 +98,13 @@ pipeline {
// steps {
// script {
// FAILED_STAGE = env.STAGE_NAME
// cloneGitopsRepo()
// setNewTestVersion()
// pushGitopsRepo()
// }
// }
// }
// }
post {
failure {
script {
......@@ -138,70 +115,52 @@ pipeline {
}
}
}
Boolean isReleaseBranch() {
return env.BRANCH_NAME == 'release-admin'
}
String generateImageTag() {
def imageTag = "${env.BRANCH_NAME}-${VERSION}"
if (isMasterBranch()) {
imageTag += "-${env.GIT_COMMIT.take(7)}"
}
return imageTag
}
Void cloneGitopsRepo() {
withCredentials([usernamePassword(credentialsId: 'jenkins-gitea-access-token', passwordVariable: 'TOKEN', usernameVariable: 'USER')]) {
sh 'git clone https://${USER}:${TOKEN}@git.ozg-sh.de/ozgcloud-devops/gitops.git'
}
configureGit()
}
Void configureGit() {
final email = "jenkins@ozg-sh.de"
final name = "jenkins"
dir("gitops") {
sh "git config user.email '${email}'"
sh "git config user.name '${name}'"
}
}
Void setNewDevVersion() {
setNewGitopsVersion("dev")
}
Void setNewTestVersion() {
setNewGitopsVersion("test")
}
Void setNewGitopsVersion(String environment) {
dir("gitops") {
def envFile = "${environment}/application/values/admin-client-values.yaml"
def envVersions = readYaml file: envFile
envVersions.admin_client.image.tag = IMAGE_TAG
envVersions.admin_client.helm.version = HELM_CHART_VERSION
writeYaml file: envFile, data: envVersions, overwrite: true
if (hasValuesFileChanged(environment)) {
sh "git add ${envFile}"
sh "git commit -m 'jenkins rollout ${environment} admin_client version ${IMAGE_TAG}'"
}
}
}
Boolean hasValuesFileChanged(String environment) {
return sh (script: "git status | grep '${environment}/application/values/admin-client-values.yaml'", returnStatus: true) == env.SH_SUCCESS_STATUS_CODE as Integer
}
Void pushGitopsRepo() {
withCredentials([usernamePassword(credentialsId: 'jenkins-gitea-access-token', passwordVariable: 'TOKEN', usernameVariable: 'USER')]) {
dir("gitops") {
......@@ -211,15 +170,12 @@ Void pushGitopsRepo() {
}
}
}
Boolean hasUnpushedCommits() {
return sh (script: "git cherry -v | grep .", returnStatus: true) == env.SH_SUCCESS_STATUS_CODE as Integer
}
Void tagAndPushDockerImage(String newTag) {
withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) {
sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}'
sh "docker tag docker.ozg-sh.de/admin-client:build-latest docker.ozg-sh.de/admin-client:${newTag}"
sh "docker push docker.ozg-sh.de/admin-client:${newTag}"
}
......@@ -230,16 +186,16 @@ String getPackagejsonVersion() {
echo packageJSONVersion
return packageJSONVersion
}
Void deployHelmChart(String helmChartVersion) {
withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
if (isReleaseBranch()) {
result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps -F file=@admin-client-'''+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=@admin-client-'''
+ helmChartVersion + '''.tgz''', returnStdout: true
}
else {
result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps-snapshot -F file=@admin-client-'''+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=@admin-client-'''
+ helmChartVersion + '''.tgz''', returnStdout: true
}
if (result != '') {
error(result)
}
......@@ -247,38 +203,31 @@ Void deployHelmChart(String helmChartVersion) {
}
String generateHelmChartVersion() {
def chartVersion = "${VERSION}"
if (isMasterBranch()) {
chartVersion += "-${env.GIT_COMMIT.take(7)}"
}
else if (!isReleaseBranch()) {
chartVersion += "-${env.BRANCH_NAME}"
}
return chartVersion.replaceAll("_", "-")
}
Boolean isMasterBranch() {
return env.BRANCH_NAME == 'master'
}
Void sendFailureMessage() {
def room = ''
def data = """{"msgtype":"m.text", \
"body":"Admin-Client: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER} Link: ${BLUE_OCEAN_URL}", \
"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>"}"""
if (isMasterBranch()) {
room = "!iQPAvQIiRwRpNOszjw:matrix.ozg-sh.de"
}
else if (isReleaseBranch()) {
room = "!oWZpUGTFsxkJIYNfYg:matrix.ozg-sh.de"
}
sh "curl -XPOST -H 'authorization: Bearer ${getElementAccessToken()}' -d '${data}' https://matrix.ozg-sh.de/_matrix/client/v3/rooms/$room/send/m.room.message"
}
String getElementAccessToken() {
withCredentials([string(credentialsId: 'element-login-json', variable: 'LOGIN_JSON')]) {
return readJSON (text: sh (script: '''curl -XPOST -d \"$LOGIN_JSON\" https://matrix.ozg-sh.de/_matrix/client/v3/login''', returnStdout: true)).access_token
......
......@@ -109,6 +109,7 @@
"ng-packagr": "18.2.1",
"nx": "19.8.8",
"prettier": "^3.2.5",
"prettier-plugin-groovy": "^0.2.1",
"prettier-plugin-organize-imports": "^4.1.0",
"prettier-plugin-tailwindcss": "^0.6.8",
"sonarqube-scanner": "^4.2.5",
......@@ -28750,6 +28751,19 @@
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/prettier-plugin-groovy": {
"version": "0.2.1",
"resolved": "http://nexus.ozg-sh.de/repository/npm-proxy/prettier-plugin-groovy/-/prettier-plugin-groovy-0.2.1.tgz",
"integrity": "sha512-89i4b9nxnQ+KKjl/rSktUA0u1HFCK3HeoqXAaHNpQC8wKjnL/FJ87pRQlDi0nrmGsWRcvGqbD1FaTgSS0EZ44Q==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=20.0.0 || ^18.12.0"
},
"peerDependencies": {
"prettier": "^3.3.3"
}
},
"node_modules/prettier-plugin-organize-imports": {
"version": "4.1.0",
"resolved": "http://nexus.ozg-sh.de/repository/npm-proxy/prettier-plugin-organize-imports/-/prettier-plugin-organize-imports-4.1.0.tgz",
......@@ -156,6 +156,7 @@
"ng-packagr": "18.2.1",
"nx": "19.8.8",
"prettier": "^3.2.5",
"prettier-plugin-groovy": "^0.2.1",
"prettier-plugin-organize-imports": "^4.1.0",
"prettier-plugin-tailwindcss": "^0.6.8",
"sonarqube-scanner": "^4.2.5",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment