FabioFratini 10 月之前
父节点
当前提交
de03c37884
共有 1 个文件被更改,包括 18 次插入7 次删除
  1. 18 7
      Jenkinsfile

+ 18 - 7
Jenkinsfile

@@ -26,7 +26,7 @@ pipeline {
         STORAGE_PATH = 'app/public/'
 
         REMOTE_HOST = '10.2.0.10'
-        REMOTE_USER = 'deploy'
+        REMOTE_USER = 'fratini'  // Changed from 'deploy' to 'fratini'
         REMOTE_DIR = '/var/www/html/polizia'
 
         ADMIN_EMAIL = 'f.fratini@webmagistri.it'
@@ -63,22 +63,33 @@ pipeline {
             }
         }
 
-        stage('Debug') {
+        stage('Debug Branch Info') {
             steps {
-                sh 'git branch --show-current || git rev-parse --abbrev-ref HEAD || echo "Cannot determine branch"'
+                sh 'git branch -v'
+                sh 'git status'
+                sh 'echo "BRANCH_NAME: ${BRANCH_NAME:-not set}"'
+                sh 'echo "GIT_BRANCH: ${GIT_BRANCH:-not set}"'
+                sh 'git rev-parse --abbrev-ref HEAD || echo "Cannot get branch name"'
+                script {
+                    // Store the branch info for later use
+                    env.CURRENT_BRANCH = sh(script: 'git rev-parse --abbrev-ref HEAD || echo "HEAD"', returnStdout: true).trim()
+                    echo "Current branch detected as: ${env.CURRENT_BRANCH}"
+                }
             }
         }
 
         stage('Deploy to Server') {
             when {
                 expression {
-                    def branch = sh(script: 'git rev-parse --abbrev-ref HEAD || echo unknown', returnStdout: true).trim()
-                    return branch == 'develop' || branch.contains('develop')
+                    // Always deploy from develop branch
+                    return env.CURRENT_BRANCH == 'HEAD' || env.CURRENT_BRANCH == 'develop' ||
+                           env.GIT_BRANCH == 'origin/develop' || env.BRANCH_NAME == 'develop'
                 }
             }
             steps {
+                echo "Starting deployment to ${REMOTE_HOST} as user ${REMOTE_USER}"
+
                 // Using SSH with identity file from Jenkins home directory
-                // Make sure to place the SSH key at /var/lib/jenkins/.ssh/id_rsa
                 sh '''
                     # Ensure SSH directory exists
                     mkdir -p ~/.ssh
@@ -106,7 +117,7 @@ pipeline {
                     php artisan optimize && \\
                     php artisan storage:link && \\
                     chmod -R 775 storage bootstrap/cache && \\
-                    chown -R www-data:www-data ."
+                    sudo chown -R www-data:www-data ."
 
                     # Restart services
                     ssh ${REMOTE_USER}@${REMOTE_HOST} "sudo systemctl restart php8.1-fpm || sudo systemctl restart php-fpm || echo 'PHP service restart failed, may need manual intervention'"