Using Jenkins2 to upload via FTP

I am using the new Jenkins2 pipeline to create a complex project using

  • node interface
  • php backend

both are in different repositories, therefore, you must use the pipeline to synchronize them, compile and prepare for deployment. I cannot find an easy way to deploy using FTP.

My script looks something like this:

node {
    // uncomment these 2 lines and edit the name 'node-4.4.5' according to what you choose in configuration
    def nodeHome = tool name: 'NodeJS 7.2.1', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
    env.PATH = "${nodeHome}/bin:${env.PATH}"

    stage("front") {
        dir('front') { // switch to subdir
            git url: ...             
            sh "npm install"

            sh "npm run build --prod"

            sh "cp -R * ../dist"
        }
    }

    stage("back") {
        dir('back') {
            git url: ...

            sh 'curl -sS https://getcomposer.org/installer | php'
            sh 'php composer.phar install'

            sh "cp -R * ../dist"
        }
    }
    stage("upload via ftp") {
        // IM NOT SURE WHAT TO DO HERE
    }
}

UPDATE 2016-12-16

To clarify what I need to do is run something like Publish via FTP, like older versions of Jenkins.

+9
source share
5 answers

Jenkins Publish Over FTP 1.15.

Jenkinsfile, :

stage('Upload')
{
    ftpPublisher alwaysPublishFromMaster: true, continueOnError: false, failOnError: false, publishers: [
        [configName: 'YOUR_CONFIG_HERE', transfers: [
            [asciiMode: false, cleanRemote: false, excludes: '', flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: "YOUR_DIRECTORY_HERE", remoteDirectorySDF: false, removePrefix: '', sourceFiles: '**.exe, **.txt']
        ], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true]
    ]
}
+10

ncftp Jenkins:

ncftpput -R -v -u "ftp-username" ftp.website.com ftp-upload-path local-path/*

( FTP? Super User)

+3

, , Linux ftp? ,

$ curl -T my-local-file.txt ftp://ftp.example.com --user user:secret
+2

Jenkins Publish Over FTP , . lftp. , , vanilla ftp.

stage('FTP') {
    steps {
        sh '''if git describe --exact-match --tags HEAD; then
            lftp ftp://USER:PWD@FTP -e "cd PATH; mput *.exe; bye"
        else
            exit 0
        fi
        '''
    }
}

FTP, git .

+1

Google, , .

, :

stage ('Deploy') {
  steps {
    ftpPublisher alwaysPublishFromMaster: true,
                 continueOnError: false,
                 failOnError: false,
                 masterNodeName: '',
                 paramPublish: null,
                 publishers: [[configName: 'External Host', transfers: [[asciiMode: false, cleanRemote: true, excludes: '', flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: 'public', sourceFiles: 'public/*,public/**/*']], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false]]
  }

  • Jenkins " FTP" , .
  • add new new required parameters masterNodeName and paramPublish with empty string and zero respectively.

In the publisher block, these parameters correspond to the parameters defined in the old-style Jenkins configuration in the Transfers section, so see Details.

I hope this helps future people deal with the ftpPublisher plugin in the pipeline.

0
source

Source: https://habr.com/ru/post/1663891/


All Articles