using Jenkins2 pipeline to upload via FTP

The Jenkins Publish Over FTP plugin has Pipeline support as of version 1.15.

A snippet from my Jenkinsfile that sends some files to our server:

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]
    ]
}

I generated this code snippet using the Jenkins snippet generator found under "Pipeline Syntax". Choose "ftpPublisher: send build artifacts over FTP" in the menu at "Sample Step", enter all details in the form and press "Generate Pipeline Script".


Since this is one of the top links on google and the other answers don't work, I'll go ahead and add my two cents.

Here is the working pipeline stage that I'm using:

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]]
  }

The magic here is

  • Set up the External Host in the main Jenkins configuration page under Publish Over FTP and make sure the names match.
  • add the new new required parameters masterNodeName and paramPublish with an empty string and null respectively.

In the publishers block, these settings match what is defined in the old style Jenkins config under transfers, so refer to that for details.

I hope that helps future folks struggling with the ftpPublisher plugin in a Pipeline.