diff --git a/Jenkinsfile b/Jenkinsfile index 34da8d565..7e0cfce54 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,6 +3,7 @@ def PROTECTED_BRANCH def FROM_GIT def RUN_TESTS +def SHOULD_BUILD pre: { switch (env.BRANCH_NAME) { @@ -27,6 +28,7 @@ pre: { FROM_GIT = env.JOB_NAME.startsWith('gitea/') RUN_TESTS = !PROTECTED_BRANCH && FROM_GIT + RUN_BUILD = PROTECTED_BRANCH && FROM_GIT // Uncomment to enable debugging // https://loopback.io/doc/en/lb3/Setting-debug-strings.html#debug-strings-reference @@ -46,57 +48,102 @@ pipeline { } stages { stage('Install') { - environment { - NODE_ENV = "" - } - parallel { - stage('Backend') { - steps { - sh 'pnpm install --prefer-offline' - } - } - stage('Frontend') { - when { - expression { FROM_GIT } - } - steps { - sh 'pnpm install --prefer-offline --prefix=front' - } - } - stage('Print') { - when { - expression { FROM_GIT } - } - steps { - sh 'pnpm install --prefer-offline --prefix=print' - } - } - } - } - stage('Test') { - when { - expression { RUN_TESTS } - } environment { NODE_ENV = "" TZ = 'Europe/Madrid' } parallel { - stage('Backend') { - steps { - sh 'npm run test:back:ci' + stage('Backend') { stages { + stage('Install') { + environment { + NODE_ENV = "" + } + parallel { + stage('Backend') { + steps { + sh 'pnpm install --prefer-offline' + } + } + stage('Print') { + when { + expression { FROM_GIT } + } + steps { + sh 'pnpm install --prefer-offline --prefix=print' + } + } + } } - } - stage('Frontend') { - steps { - sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=10' + stage('Test') { + when { + expression { RUN_TESTS } + } + environment { + NODE_ENV = "" + } + steps { + sh 'npm run test:back:ci' + } + post { + always { + script { + try { + junit 'junitresults.xml' + junit 'junit.xml' + } catch (e) { + echo e.toString() + } + } + } + } } - } + stage('Build') { + when { + expression { RUN_BUILD } + } + steps { + sh 'docker-compose build back' + } + } + }} + stage('Frontend') { stages { + stage('Install') { + when { + expression { FROM_GIT } + } + environment { + NODE_ENV = "" + } + steps { + sh 'pnpm install --prefer-offline --prefix=front' + } + } + stage('Test') { + when { + expression { RUN_TESTS } + } + environment { + NODE_ENV = "" + } + steps { + sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=10' + } + } + stage('Build') { + when { + expression { RUN_BUILD } + } + steps { + sh 'gulp build' + sh 'docker-compose build front' + } + } + }} } } stage('Build') { when { - expression { PROTECTED_BRANCH && FROM_GIT } + expression { RUN_BUILD } } environment { CREDENTIALS = credentials('docker-registry') @@ -106,7 +153,6 @@ pipeline { def packageJson = readJSON file: 'package.json' env.VERSION = packageJson.version } - sh 'gulp build' dockerBuild() } }