พัฒนา web application ด้วย Java

jenkins pipeline upload file ไปยัง server ด้วย fpt

 pipeline {

    agent any
    environment {
        // Define FTP server details
        FTP_SERVER = "ftp.example.com"
        FTP_REMOTE_DIR = "/public_html"
        // Reference the stored Jenkins credential ID
        FTP_CRED_ID = 'my-ftp-credentials' 
    }
    stages {
        stage('Checkout Code') {
            steps {
                // Ensures a full checkout, necessary for git-ftp to calculate changes
                checkout scm 
            }
        }
        stage('Deploy Changed Files via FTP') {
            steps {
                // Use the 'withCredentials' step to access the FTP username and password securely
                withCredentials([usernamePassword(credentialsId: env.FTP_CRED_ID, usernameVariable: 'FTP_USER', passwordVariable: 'FTP_PASS')]) {
                    sh '''
                    # Configure git-ftp with server details and credentials from environment variables
                    git ftp init --user "$FTP_USER" --passwd "$FTP_PASS" "$FTP_SERVER$FTP_REMOTE_DIR" || true

                    # Push only the changed files since the last sync
                    git ftp push --user "$FTP_USER" --passwd "$FTP_PASS" "$FTP_SERVER$FTP_REMOTE_DIR"
                    '''
                }
            }
        }
    }
}
jenkins pipeline upload file ไปยัง server ด้วย fpt jenkins pipeline upload file ไปยัง server ด้วย fpt Reviewed by Mr.Boonchai on พฤศจิกายน 26, 2568 Rating: 5

ไม่มีความคิดเห็น:

Thank you

ขับเคลื่อนโดย Blogger.