FabioFratini 10 mesi fa
parent
commit
7ab00c5a2b
1 ha cambiato i file con 54 aggiunte e 10 eliminazioni
  1. 54 10
      Jenkinsfile

+ 54 - 10
Jenkinsfile

@@ -30,6 +30,11 @@ pipeline {
         REMOTE_DIR = '/var/www/html/polizia'
         REMOTE_DIR = '/var/www/html/polizia'
 
 
         ADMIN_EMAIL = 'f.fratini@webmagistri.it'
         ADMIN_EMAIL = 'f.fratini@webmagistri.it'
+
+        // PHP version to install if needed
+        PHP_VERSION = '8.1'
+        // Node version to install if needed
+        NODE_VERSION = '18.x'
     }
     }
 
 
     stages {
     stages {
@@ -40,12 +45,51 @@ pipeline {
                 sh 'whoami'
                 sh 'whoami'
             }
             }
         }
         }
-        stage('Setup') {
+
+        stage('Setup Tools') {
             steps {
             steps {
-                sh 'php --version || echo "PHP not available"'
-                sh 'composer --version || echo "Composer not available"'
-                sh 'node --version || echo "Node not available"'
-                sh 'npm --version || echo "NPM not available"'
+                script {
+                    // Check and install PHP if not available
+                    def phpInstalled = sh(script: 'php --version', returnStatus: true)
+                    if (phpInstalled != 0) {
+                        echo "Installing PHP ${PHP_VERSION}..."
+                        sh """
+                            sudo apt-get update
+                            sudo apt-get install -y software-properties-common
+                            sudo add-apt-repository -y ppa:ondrej/php
+                            sudo apt-get update
+                            sudo apt-get install -y php${PHP_VERSION} php${PHP_VERSION}-cli php${PHP_VERSION}-common php${PHP_VERSION}-curl php${PHP_VERSION}-mbstring php${PHP_VERSION}-mysql php${PHP_VERSION}-xml php${PHP_VERSION}-zip
+                        """
+                    }
+
+                    // Check and install Composer if not available
+                    def composerInstalled = sh(script: 'composer --version', returnStatus: true)
+                    if (composerInstalled != 0) {
+                        echo "Installing Composer..."
+                        sh """
+                            php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
+                            php composer-setup.php --install-dir=/usr/local/bin --filename=composer
+                            php -r "unlink('composer-setup.php');"
+                            chmod +x /usr/local/bin/composer
+                        """
+                    }
+
+                    // Check and install Node.js and NPM if not available
+                    def nodeInstalled = sh(script: 'node --version', returnStatus: true)
+                    if (nodeInstalled != 0) {
+                        echo "Installing Node.js ${NODE_VERSION}..."
+                        sh """
+                            curl -sL https://deb.nodesource.com/setup_${NODE_VERSION} | sudo -E bash -
+                            sudo apt-get install -y nodejs
+                        """
+                    }
+                }
+
+                // Verify installations
+                sh 'php --version'
+                sh 'composer --version'
+                sh 'node --version'
+                sh 'npm --version'
             }
             }
         }
         }
 
 
@@ -57,22 +101,22 @@ pipeline {
 
 
         stage('Install Dependencies') {
         stage('Install Dependencies') {
             steps {
             steps {
-                sh 'composer install --no-interaction --no-progress --prefer-dist || echo "Skipping composer install"'
+                sh 'composer install --no-interaction --no-progress --prefer-dist'
             }
             }
         }
         }
 
 
         stage('Setup Environment') {
         stage('Setup Environment') {
             steps {
             steps {
                 sh 'php artisan key:generate || echo "Skipping key generation"'
                 sh 'php artisan key:generate || echo "Skipping key generation"'
-                sh 'php artisan config:clear || echo "Skipping config clear"'
-                sh 'php artisan cache:clear || echo "Skipping cache clear"'
+                sh 'php artisan config:clear'
+                sh 'php artisan cache:clear'
             }
             }
         }
         }
 
 
         stage('Build Assets') {
         stage('Build Assets') {
             steps {
             steps {
-                sh 'npm install || echo "Skipping npm install"'
-                sh 'npm run build || echo "Skipping npm build"'
+                sh 'npm install'
+                sh 'npm run build'
             }
             }
         }
         }