Files
tatort/Jenkinsfile
Chi Cong Tran e66de4059e
All checks were successful
InnoHub Processor/tatort/pipeline/head This commit looks good
add testing state for Jenkins
2025-09-05 08:41:37 +02:00

144 lines
4.3 KiB
Groovy

/* groovylint-disable-next-line UnusedVariable */
@Library('InnoHub-Library') _
def didRun = false
def versionTag = 'null'
pipeline {
agent any
tools {
nodejs 'NodeJS-24.2.0'
}
environment {
REGISTRY = 'https://gitea.innovation-hub-niedersachsen.de/'
USER = 'jenkins'
TOKEN = credentials('JenkinsGitea')
}
parameters {
string(name: 'REPO_NAME', defaultValue: '', description: 'Repo Name')
string(name: 'GIT_REF', defaultValue: '', description: 'Git Ref')
}
options {
buildDiscarder(
BuildHistoryManager([
[ continueAfterMatch: false, matchAtMost: 5 ],
[ actions: [ DeleteBuild() ] ]
])
)
}
stages {
stage('Set Version Tag') {
steps {
script {
versionTag = generateVersionTag(params.GIT_REF)
echo "[INFO] Using VERSION_TAG: ${versionTag}"
}
}
}
stage('Validate Repository') {
steps {
script {
checkRepoName(params.REPO_NAME, true)
}
}
}
stage('Install Dependencies') {
steps {
script {
didRun = true
}
sh 'npm ci'
}
}
stage('Security Audit') {
steps {
script {
didRun = true
}
echo 'Start checking security vulnerabilities in npm packages'
sh 'npm audit --audit-level=moderate'
}
}
stage('Run Tests') {
steps {
sh 'npm run test'
}
}
stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('sonarqube') {
sh 'sonar-scanner -Dsonar.projectKey=tatort -Dsonar.sources=src'
}
}
}
stage('Push image to gitea registry') {
when {
branch 'development'
}
steps {
script {
def imageName = "gitea.innovation-hub-niedersachsen.de/innohub/tatort-dev"
docker.withRegistry(REGISTRY, 'JenkinsGitea') {
def img = docker.build("${imageName}:${versionTag}", '-f Dockerfile.dev .')
img.push()
img.push('latest')
}
didRun = true
}
}
}
stage('Update Helm Chart Repository') {
when {
branch 'development'
}
steps {
script {
updateHelmChart([
tag: versionTag,
repoUrl: 'gitea.innovation-hub-niedersachsen.de/innohub/charts.git',
chartPath: 'tatort-dev/tatort',
chartName: 'tatort',
imageRepo: 'gitea.innovation-hub-niedersachsen.de/innohub/tatort-dev',
credentialsId: 'JenkinsGitea',
branch: 'main'
])
didRun = true
}
}
}
}
post {
success {
script {
if (didRun) {
echo 'Pipeline erfolgreich!'
discordSend description: "Running ${env.BUILD_ID} on ${env.JENKINS_URL}, ${params.GIT_REF}", footer: 'Pipeline succeeded', link: env.BUILD_URL, result: currentBuild.currentResult, title: env.JOB_NAME, webhookURL: 'https://discordapp.com/api/webhooks/1389470542691831819/NdMO17sLBG2dplp_-oh6Ff0cbPOoADl0QwXKM9UzduxU44av_ZQkQjKTmpdK7YuwcZDc'
}
}
}
failure {
script {
if (didRun) {
echo 'Pipeline fehlgeschlagen!'
discordSend description: "Running ${env.BUILD_ID} on ${env.JENKINS_URL}, ${params.GIT_REF}", footer: 'Pipeline failed', link: env.BUILD_URL, result: currentBuild.currentResult, title: env.JOB_NAME, webhookURL: 'https://discordapp.com/api/webhooks/1389470542691831819/NdMO17sLBG2dplp_-oh6Ff0cbPOoADl0QwXKM9UzduxU44av_ZQkQjKTmpdK7YuwcZDc'
}
}
}
}
}