fix: refs #5483 Jenkinsfile codefix
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Juan Ferrer 2024-01-30 21:49:58 +01:00
parent 4d065a2f79
commit 420398260f
1 changed files with 19 additions and 14 deletions

33
Jenkinsfile vendored
View File

@ -1,4 +1,9 @@
#!/usr/bin/env groovy
def PROTECTED_BRANCH
def FROM_GIT
def RUN_TESTS
pipeline {
agent any
options {
@ -33,19 +38,19 @@ pipeline {
def packageJson = readJSON file: 'package.json'
env.VERSION = packageJson.version
env.PROTECTED_BRANCH = [
'dev',
'test',
'master'
].contains(env.BRANCH_NAME)
env.GIT_COMMIT_MSG = sh(
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
PROTECTED_BRANCH = [
'dev',
'test',
'master'
].contains(env.BRANCH_NAME)
FROM_GIT = JOB_NAME.startsWith('gitea/')
RUN_TESTS = !PROTECTED_BRANCH && FROM_GIT
}
setEnv()
}
@ -74,7 +79,7 @@ pipeline {
}
stage('Test') {
when {
expression { return env.RUN_TESTS }
expression { return RUN_TESTS }
}
environment {
NODE_ENV = ""
@ -95,7 +100,7 @@ pipeline {
}
stage('Build') {
when {
expression { return env.PROTECTED_BRANCH && env.FROM_GIT }
expression { return PROTECTED_BRANCH && FROM_GIT }
}
environment {
CREDENTIALS = credentials('docker-registry')
@ -107,7 +112,7 @@ pipeline {
}
stage('Deploy') {
when {
expression { return env.PROTECTED_BRANCH }
expression { return PROTECTED_BRANCH }
}
parallel {
stage('Database') {
@ -125,7 +130,7 @@ pipeline {
}
stage('Docker') {
when {
expression { return env.FROM_GIT }
expression { return FROM_GIT }
}
environment {
DOCKER_HOST = "${env.SWARM_HOST}"
@ -140,7 +145,7 @@ pipeline {
post {
always {
script {
if (env.RUN_TESTS) {
if (RUN_TESTS) {
try {
junit 'junitresults.xml'
junit 'junit.xml'
@ -152,7 +157,7 @@ pipeline {
}
success {
script {
if (env.BRANCH_NAME == 'master' && env.FROM_GIT) {
if (env.BRANCH_NAME == 'master' && FROM_GIT) {
String message = env.GIT_COMMIT_MSG
int index = message.indexOf('\n')
if (index != -1)