diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index ad1f7e32b..7409124f5 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -1065,6 +1065,62 @@ def ftp(registry, xml_parent, data): XML.SubElement(transfer_node, 'asciiMode').text = 'false' +def ftp_publisher(registry, xml_parent, data): + """yaml: ftp-publisher + This plugin can be used to upload project artifacts and whole directories + to an ftp server. + Requires the Jenkins :jenkins-wiki:`FTP-Publisher Plugin + `. + + :arg list uploads: List of files to upload + + :uploads: + * **file-path** ('str') -- Destination folder. It will be created + if doesn't exists. Created relative to ftp root directory. + (default '') + * **source-file** ('str') -- Source files which will be uploaded + (default '') + :arg str site-name: Name of FTP server to upload to (required) + :arg bool use-timestamps: Use timestamps in the FTP directory path (default + false) + :arg bool flatten-files: Flatten files on the FTP host (default false) + :arg bool skip-publishing: Skip publishing (default false) + + Minimal Example: + + .. literalinclude:: + /../../tests/publishers/fixtures/ftp-publisher-minimal.yaml + :language: yaml + + Full Example: + + .. literalinclude:: + /../../tests/publishers/fixtures/ftp-publisher-full.yaml + :language: yaml + """ + ftp = XML.SubElement(xml_parent, 'com.zanox.hudson.plugins.FTPPublisher') + ftp.set('plugin', 'ftppublisher') + + entries = XML.SubElement(ftp, 'entries') + if 'uploads' in data: + upload_mapping = [ + ('file-path', 'filePath', ''), + ('source-file', 'sourceFile', ''), + ] + for upload in data['uploads']: + entry = XML.SubElement(entries, 'com.zanox.hudson.plugins.Entry') + helpers.convert_mapping_to_xml( + entry, upload, upload_mapping, fail_required=True) + + mapping = [ + ('site-name', 'siteName', None), + ('use-timestamps', 'useTimestamps', False), + ('flatten-files', 'flatten', False), + ('skip-publishing', 'skip', False), + ] + helpers.convert_mapping_to_xml(ftp, data, mapping, fail_required=True) + + def junit(registry, xml_parent, data): """yaml: junit Publish JUnit test results. diff --git a/tests/publishers/fixtures/ftp-publisher-full.xml b/tests/publishers/fixtures/ftp-publisher-full.xml new file mode 100644 index 000000000..e85e8afa2 --- /dev/null +++ b/tests/publishers/fixtures/ftp-publisher-full.xml @@ -0,0 +1,21 @@ + + + + + + + destination/folder + folder/dist/*.jar + + + foo/bar + foo/bar/*.ear + + + foo + true + true + true + + + diff --git a/tests/publishers/fixtures/ftp-publisher-full.yaml b/tests/publishers/fixtures/ftp-publisher-full.yaml new file mode 100644 index 000000000..44b194131 --- /dev/null +++ b/tests/publishers/fixtures/ftp-publisher-full.yaml @@ -0,0 +1,11 @@ +publishers: + - ftp-publisher: + uploads: + - file-path: destination/folder + source-file: folder/dist/*.jar + - file-path: foo/bar + source-file: foo/bar/*.ear + site-name: foo + use-timestamps: true + flatten-files: true + skip-publishing: true diff --git a/tests/publishers/fixtures/ftp-publisher-minimal.xml b/tests/publishers/fixtures/ftp-publisher-minimal.xml new file mode 100644 index 000000000..ab736f8f6 --- /dev/null +++ b/tests/publishers/fixtures/ftp-publisher-minimal.xml @@ -0,0 +1,12 @@ + + + + + + foo + false + false + false + + + diff --git a/tests/publishers/fixtures/ftp-publisher-minimal.yaml b/tests/publishers/fixtures/ftp-publisher-minimal.yaml new file mode 100644 index 000000000..76b31cee6 --- /dev/null +++ b/tests/publishers/fixtures/ftp-publisher-minimal.yaml @@ -0,0 +1,3 @@ +publishers: + - ftp-publisher: + site-name: foo