Add support for the S3 Publisher plugin

Change-Id: Ia918596276e49d5876bc232fce760e270a829335
This commit is contained in:
Benjamin Staffin 2014-10-13 21:09:58 -07:00
parent 445c73a298
commit 1d08abd8f0
4 changed files with 119 additions and 0 deletions

View File

@ -3533,6 +3533,79 @@ def artifact_deployer(parser, xml_parent, data):
XML.SubElement(deployer, 'deployEvenBuildFail').text = deploy_if_fail
def s3(parser, xml_parent, data):
"""yaml: s3
Upload build artifacts to Amazon S3.
Requires the Jenkins `S3 plugin.
<https://wiki.jenkins-ci.org/display/JENKINS/S3+Plugin>`_
:arg str s3-profile: Globally-defined S3 profile to use
:arg list entries:
:entries:
* **destination-bucket** (`str`) - Destination S3 bucket
* **source-files** (`str`) - Source files (Ant glob syntax)
* **storage-class** (`str`) - S3 storage class; one of "STANDARD"
or "REDUCED_REDUNDANCY"
* **bucket-region** (`str`) - S3 bucket region (capitalized with
underscores)
* **upload-on-failure** (`bool`) - Upload files even if the build
failed (Default: False)
* **upload-from-slave** (`bool`) - Perform the upload directly from
the Jenkins slave rather than the master node. (Default: False)
* **managed-artifacts** (`bool`) - Let Jenkins fully manage the
published artifacts, similar to when artifacts are published to
the Jenkins master. (Default: False)
:arg list metadata-tags:
:metadata-tags:
* **key** Metadata key for files from this build. It will be
prefixed by "x-amz-meta-" when uploaded to S3. Can contain macros
(e.g. environment variables).
* **value** Metadata value associated with the key. Can contain macros.
Example:
.. literalinclude:: /../../tests/publishers/fixtures/s3001.yaml
:language: yaml
"""
deployer = XML.SubElement(xml_parent,
'hudson.plugins.s3.S3BucketPublisher')
if data is None or not data.get('entries'):
raise JenkinsJobsException('No filesets defined.')
XML.SubElement(deployer, 'profileName').text = data.get('s3-profile')
entries = XML.SubElement(deployer, 'entries')
for entry in data.get('entries'):
fileset = XML.SubElement(entries, 'hudson.plugins.s3.Entry')
# xml keys -> yaml keys
settings = [('bucket', 'destination-bucket', ''),
('sourceFile', 'source-files', ''),
('storageClass', 'storage-class', ''),
('selectedRegion', 'bucket-region', ''),
('noUploadOnFailure', 'upload-on-failure', False),
('uploadFromSlave', 'upload-from-slave', False),
('managedArtifacts', 'managed-artifacts', False)]
for xml_key, yaml_key, default in settings:
xml_config = XML.SubElement(fileset, xml_key)
config_value = entry.get(yaml_key, default)
if xml_key == 'noUploadOnFailure':
xml_config.text = str(not config_value).lower()
elif isinstance(default, bool):
xml_config.text = str(config_value).lower()
else:
xml_config.text = str(config_value)
metadata = XML.SubElement(deployer, 'userMetadata')
for tag in data.get('metadata-tags', []):
pair = XML.SubElement(metadata, 'hudson.plugins.s3.MetadataPair')
XML.SubElement(pair, 'key').text = tag.get('key')
XML.SubElement(pair, 'value').text = tag.get('value')
def ruby_metrics(parser, xml_parent, data):
"""yaml: ruby-metrics
Rcov plugin parses rcov html report files and

View File

@ -155,6 +155,7 @@ jenkins_jobs.publishers =
rich-text-publisher=jenkins_jobs.modules.publishers:rich_text_publisher
robot=jenkins_jobs.modules.publishers:robot
ruby-metrics=jenkins_jobs.modules.publishers:ruby_metrics
s3=jenkins_jobs.modules.publishers:s3
scp=jenkins_jobs.modules.publishers:scp
sitemonitor=jenkins_jobs.modules.publishers:sitemonitor
sloccount=jenkins_jobs.modules.publishers:sloccount

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.s3.S3BucketPublisher>
<profileName>banana</profileName>
<entries>
<hudson.plugins.s3.Entry>
<bucket>herp-derp</bucket>
<sourceFile>bargle_${BUILD_ID}.tgz</sourceFile>
<storageClass>STANDARD</storageClass>
<selectedRegion>US_EAST_1</selectedRegion>
<noUploadOnFailure>true</noUploadOnFailure>
<uploadFromSlave>true</uploadFromSlave>
<managedArtifacts>true</managedArtifacts>
</hudson.plugins.s3.Entry>
</entries>
<userMetadata>
<hudson.plugins.s3.MetadataPair>
<key>warbl ${garbl}</key>
<value>herp derp weevils</value>
</hudson.plugins.s3.MetadataPair>
<hudson.plugins.s3.MetadataPair>
<key>hurrdurr</key>
<value>wharrgarbl blee ${FANCY_VARIABLE}</value>
</hudson.plugins.s3.MetadataPair>
</userMetadata>
</hudson.plugins.s3.S3BucketPublisher>
</publishers>
</project>

View File

@ -0,0 +1,16 @@
publishers:
- s3:
s3-profile: banana
entries:
- destination-bucket: herp-derp
source-files: 'bargle_${BUILD_ID}.tgz'
storage-class: STANDARD
bucket-region: US_EAST_1
upload-on-failure: false
upload-from-slave: true
managed-artifacts: true
metadata-tags:
- key: warbl ${garbl}
value: herp derp weevils
- key: hurrdurr
value: wharrgarbl blee ${FANCY_VARIABLE}