0

I created this pipeline with Jenkins in my project. Now I need to deploy the project to the server with FTP by using this code :

bat  'git ftp init --user xxxxxx--passwd xxxxxxxftp://193.141.64.96/public_html'

but it does not upload anything to the server. What's the problem? How can I upload my project with Jenkins and FTP?

pipeline {
    
    agent any;

    parameters{
        choice(name: 'CHOICE', choices: ['One', 'Two', 'Three'], description: 'Pick something')
        booleanParam(name:'executeTests',defaultValue:true,description:'')
    }

    triggers {
        pollSCM('*/1 * * * *')
    }
    
    environment {
        ACCESS_KEY_FTP_USERNAME = credentials('FTP_FILE_UPLOAD_USERNAME');
        ACCESS_KEY_FTP_PASSWORD = credentials(' FTP_FILEUPLOAD_PASSWORD');
    }

    stages {
        stage('Install  npm') {
                steps {
                    bat 'npm install'
                }
                post {
                    always {
                        echo 'Start npm install'
                    }
                    failure {
                        echo 'fail operation npm installr'
                        mail body: 'Error in npm install ', subject: 'Build failed!', to: 'kiadr9372@gmail.com'
                    }
                    success {
                        echo 'Success npm install'
                    }
                }
            }

        stage('Test') {
            when {
                expression {
                    params.executeTests
                }
            }
            steps{
                echo 'Testing the application'
                // echo "Testing Version ${NEW_VERSION}"
            }
             post {
                    always {
                        echo 'Success npm install'
                    }
                    failure {
                        echo 'fail operation npm installr'
                        mail body: 'Error in npm install ', subject: 'Build failed!', to: 'kiadr9372@gmail.com'
                    }
                    success {
                        echo 'Success npm install'
                    }
                }}
        stage('Build Project Develop') {
                when {
                    branch 'publish'
                }
                parallel {
                    stage('build') {
                        steps {
                            bat 'npm run build '
                        }
                    }
                    stage('build B') {
                            steps { 
                                echo ACCESS_KEY_FTP_USERNAME
                                echo ACCESS_KEY_FTP_PASSWORD
                            }
                    }
                }
                post {
                    always {
                        echo 'Success Build Project'
                    }
                    failure {
                        echo 'fail operation Build Project'
                        mail body: 'Error in Build Project ', subject: 'Build failed!', to: 'kiadr9372@gmail.com'
                    }
                    success {
                        echo 'Success Build Project'
                         mail body: 'Build Success ', subject: 'Build Success!', to: 'kiadr9372@gmail.com'
                    }
                }
            }

            stage('Deploy Project (Test - Develop)') {
                when {
                    branch 'publish'
                }
                steps {
                        dir('dist')
                        {
                            dir('TestCICD')
                            {
                               bat 'npm run build '
                               bat  'git ftp init --user xxxxxx--passwd xxxxxxxftp://193.141.64.96/public_html'
                            }
                        }
                }
                post {
                    always {
                        echo 'Success Build Project'
                    }
                    failure {
                        echo 'fail operation Build Project'
                        mail body: 'Error in Build Project ', subject: 'Build failed!', to: 'kiadr9372@gmail.com'
                    }
                    success {
                        echo 'Success Build Project'
                         mail body: 'Build Success ', subject: 'Build Success!', to: 'kiadr9372@gmail.com'
                    }
                }
            }

        stage('Build Project Realase') {
                when {
                    branch 'master'
                }
                steps {
                    bat label: '', script:  'ng build --prod '
                }
                post {
                    always {
                        echo 'Success Build Project'
                    }
                    failure {
                        echo 'fail operation Build Project'
                        mail body: 'Error in Build Project ', subject: 'Build failed!', to: 'kiadr9372@gmail.com'
                    }
                    success {
                        echo 'Success Build Project'
                         mail body: 'Build Success ', subject: 'Build Success!', to: 'kiadr9372@gmail.com'
                    }
                }
            }
    }
}
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
Mr Coder
  • 761
  • 2
  • 13
  • 34
  • Please add the (relevant part[s] of the) Console Output of your build to your question. Please add `git.bat`'s source to your question. – Gerold Broser Aug 15 '21 at 18:09

1 Answers1

0

Editorial note: I'm going to update this answer as soon as the information requested in my comment above are given.

Apart from the FTP issue. It's better/safer to supply your user credentials via the Credentials Binding Plugin/withCredentials. See this answer for an example how to do that. In short:

        stage( 'Deploy Project (Test - Develop)' ) {
            steps {
                script {
                    withCredentials([usernamePassword(
                            credentialsId: 'ftp-user',
                            passwordVariable: 'password',
                            usernameVariable: 'username')]) {

                    println "${username}:${password}"
                    ...      
                    }
                }
            }
        }

In your post sections you could use a Shared Library rather than repeating commands.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • thank you sir , but i need to publish that on the server with FTP . my prtoblen is this : `how can publish the project on the server with CICD in Windows 10 ?` or with internal module of jenkines – Mr Coder Aug 16 '21 at 08:33
  • @Kianoush You're welcome. However, if you don't supply the requested information I'm terribly sorry but I can't help you any further. If there are sensitive information in these files anonymize them before posting here. – Gerold Broser Aug 16 '21 at 08:41