Files
PVM/Jenkinsfile.groovy
AnthonyS 9c5fa2cafd
All checks were successful
PVM/pipeline/head This commit looks good
Rimossa cartella exports in docker build e creato dockerfile separato per dev
2025-07-23 15:47:45 +02:00

135 lines
8.0 KiB
Groovy

def defineNodeEnv() {
if (env.BRANCH_NAME == "master" || env.BRANCH_NAME.startsWith('main/')){
return 'production'
} else {
return 'development'
}
}
pipeline {
agent any
options {
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
disableConcurrentBuilds()
skipDefaultCheckout true
}
environment {
AZIENDA = "integry"
NODE_ENV = defineNodeEnv()
}
stages {
stage("Prepare Ws") {
steps {
cleanWs deleteDirs: true, patterns: [[pattern: 'exports/', type: 'INCLUDE']]
checkout scm
}
}
stage("Build") {
steps {
script {
bat 'cd public_html && composer install --no-dev -o'
if (!env.BRANCH_NAME.startsWith('feature/')) {
echo "Building ${env.NODE_ENV} version"
nodejs('NodeJS 20.10.0') {
bat 'npm install'
bat 'npm run build'
// bat 'cd public_html && npm install --omit=dev'
if (env.NODE_ENV == 'development') {
bat '7za a public_html.zip "%WORKSPACE%\\public_html" -tzip'
} else if (env.NODE_ENV == 'production') {
bat 'grunt BuildAll'
}
}
}
stash excludes: 'exports,public_html.zip', name: 'docker-ws'
}
}
}
stage("Deploy") {
parallel {
stage("Update Master") {
steps {
script {
if (env.BRANCH_NAME == 'develop') {
archiveArtifacts artifacts: 'public_html.zip', onlyIfSuccessful: true
sshPublisher(publishers: [sshPublisherDesc(configName: 'Production Linux Web Server (192.168.3.13)', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'sudo /bin/chmod -R 777 /var/www/dev/pvm/cache', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
ftpPublisher alwaysPublishFromMaster: false, masterNodeName: '',
paramPublish: [parameterName: ""], continueOnError: false, failOnError: false,
publishers: [[configName: 'Production Linux Web Server (ftp.studioml.it)', transfers: [[asciiMode: false, cleanRemote: true, excludes: '', flatten: false, makeEmptyDirs: true, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/dev/pvm', remoteDirectorySDF: false, removePrefix: 'public_html/', sourceFiles: 'public_html/']], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false]]
sshPublisher(publishers: [
sshPublisherDesc(configName: 'Production Linux Web Server (192.168.3.13)',
transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '''sudo /bin/mkdir /var/www/dev/pvm/cache
sudo /bin/chmod -R 777 /var/www/dev/pvm/cache''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false,
patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false,
removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false,
useWorkspaceInPromotion: false, verbose: false)])
} else if (env.BRANCH_NAME == 'master') {
archiveArtifacts artifacts: 'exports\\*.zip', onlyIfSuccessful: true
sshPublisher(publishers: [sshPublisherDesc(configName: 'Production Linux Web Server (192.168.3.13)', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'sudo /bin/chmod -R 777 /var/www/portale/cache', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
ftpPublisher alwaysPublishFromMaster: false, masterNodeName: '',
paramPublish: [parameterName: ""], continueOnError: false, failOnError: false,
publishers: [[configName: 'Production Linux Web Server (ftp.studioml.it)', transfers: [[asciiMode: false, cleanRemote: true, excludes: 'public_html/cache/', flatten: false, makeEmptyDirs: true, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/portale', remoteDirectorySDF: false, removePrefix: 'public_html/', sourceFiles: 'public_html/']], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false]]
sshPublisher(publishers: [
sshPublisherDesc(configName: 'Production Linux Web Server (192.168.3.13)',
transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '''sudo /bin/mkdir /var/www/portale/cache
sudo /bin/chmod -R 777 /var/www/portale/cache''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false,
patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false,
removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false,
useWorkspaceInPromotion: false, verbose: false)])
}
}
}
}
stage('Publish on Azure') {
steps {
script {
if (env.NODE_ENV == 'production') {
azureUpload fileShareName: 'storage-ci', filesPath: 'exports/*.zip', removePrefixPath: 'exports/', storageCredentialId: '83a86793-c1d6-4776-b20f-1ff652a57fee', storageType: 'filestorage', uploadArtifactsOnlyIfSuccessful: true, verbose: true, virtualPath: "pvm/${env.BRANCH_NAME}"
}
}
}
}
stage('Docker Build') {
steps {
node('server-build') {
cleanWs()
unstash 'docker-ws'
echo "Building Docker image"
script {
def branchVersion = ""
if (env.BRANCH_NAME != "master") {
branchVersion = "-${env.BRANCH_NAME.toLowerCase().replace('/', '-')}"
}
def target = "final-prod"
if (env.NODE_ENV == "development") {
target = "final-dev"
}
bat """
docker buildx build --platform linux/amd64 --push -t "git.studioml.it/integry/pvm${branchVersion}:latest" --build-arg NODE_ENV=${env.NODE_ENV} --build-arg BUILD_VERSION=${env.BUILD_TAG.replace(' ', '-')} --target ${target} .
"""
}
}
}
}
}
}
}
}