fix: refs #5483 Jenkinsfile fixes, global nodejs tool
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Juan Ferrer 2024-01-30 21:37:20 +01:00
parent 4251f29a17
commit 4d065a2f79
1 changed files with 29 additions and 41 deletions

56
Jenkinsfile vendored
View File

@ -8,6 +8,9 @@ pipeline {
PROJECT_NAME = 'salix'
STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}"
}
tools {
nodejs 'node-v20'
}
stages {
stage('Checkout') {
steps {
@ -30,8 +33,6 @@ pipeline {
def packageJson = readJSON file: 'package.json'
env.VERSION = packageJson.version
env.FROM_GIT = env.JOB_NAME.startsWith('gitea/')
env.PROTECTED_BRANCH = [
'dev',
'test',
@ -42,6 +43,9 @@ pipeline {
script: 'git log -1 --pretty=%B ${GIT_COMMIT}',
returnStdout: true
).trim()
env.FROM_GIT = env.JOB_NAME.startsWith('gitea/')
env.RUN_TESTS = !env.PROTECTED_BRANCH && env.FROM_GIT
}
setEnv()
}
@ -53,31 +57,24 @@ pipeline {
parallel {
stage('Backend') {
steps {
nodejs('node-v20') {
sh 'npm install --no-audit --prefer-offline'
}
}
}
stage('Frontend') {
steps {
nodejs('node-v20') {
sh 'npm install --no-audit --prefer-offline --prefix=front'
}
}
}
stage('Print') {
steps {
nodejs('node-v20') {
sh 'npm install --no-audit --prefer-offline --prefix=print'
}
}
}
}
}
stage('Test') {
when {
expression { return env.FROM_GIT }
expression { return !env.PROTECTED_BRANCH }
expression { return env.RUN_TESTS }
}
environment {
NODE_ENV = ""
@ -86,33 +83,25 @@ pipeline {
parallel {
stage('Backend') {
steps {
nodejs('node-v20') {
sh 'npm run test:back:ci'
}
}
}
stage('Frontend') {
steps {
nodejs('node-v20') {
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=6'
}
}
}
}
}
stage('Build') {
when {
expression { return env.FROM_GIT }
expression { return env.PROTECTED_BRANCH }
expression { return env.PROTECTED_BRANCH && env.FROM_GIT }
}
environment {
CREDENTIALS = credentials('docker-registry')
}
steps {
nodejs('node-v20') {
sh 'gulp build'
}
dockerBuild()
}
}
@ -130,11 +119,10 @@ pipeline {
sh 'mkdir -p db/remotes'
sh 'cp "$MYSQL_CONFIG" db/remotes/$NODE_ENV.ini'
}
nodejs('node-v20') {
sh 'npx myt push $NODE_ENV --force --commit'
}
}
}
stage('Docker') {
when {
expression { return env.FROM_GIT }
@ -150,9 +138,21 @@ pipeline {
}
}
post {
always {
script {
if (env.RUN_TESTS) {
try {
junit 'junitresults.xml'
junit 'junit.xml'
} catch (e) {
echo e.toString()
}
}
}
}
success {
script {
if (env.FROM_GIT && env.BRANCH_NAME == 'master') {
if (env.BRANCH_NAME == 'master' && env.FROM_GIT) {
String message = env.GIT_COMMIT_MSG
int index = message.indexOf('\n')
if (index != -1)
@ -171,17 +171,5 @@ pipeline {
unsuccessful {
sendEmail()
}
always {
script {
if (env.FROM_GIT && !env.PROTECTED_BRANCH) {
try {
junit 'junitresults.xml'
junit 'junit.xml'
} catch (e) {
echo e.toString()
}
}
}
}
}
}