This module provides a class called Artifact which allows you to download objects from the server
and also access them as a stream.
"""
-from __future__ import with_statement
import os
import logging
import hashlib
-from jenkinsapi.exceptions import ArtifactBroken
from jenkinsapi.fingerprint import Fingerprint
+from jenkinsapi.exceptions import ArtifactBroken
log = logging.getLogger(__name__)
Grab the text of the artifact
"""
response = self.get_jenkins_obj().requester.get_and_confirm_status(self.url)
- return response.text
+ return response.content
def _do_download(self, fspath):
"""
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.tasks.Shell>
- <command>ping -c 5 localhost | tee out.txt</command>
+ <command>ping -c 5 localhost | tee out.txt
+gzip < out.txt > out.gz</command>
</hudson.tasks.Shell>
</builders>
<publishers>
<hudson.tasks.ArtifactArchiver>
- <artifacts>*.txt</artifacts>
+ <artifacts>*.txt,*.gz</artifacts>
<latestOnly>false</latestOnly>
</hudson.tasks.ArtifactArchiver>
<hudson.tasks.Fingerprinter>
'''
import os
import time
+import gzip
import shutil
import tempfile
import unittest
from jenkinsapi_tests.systests.job_configs import JOB_WITH_ARTIFACTS
from jenkinsapi_tests.test_utils.random_strings import random_string
+
class TestPingerJob(BaseSystemTest):
def test_invoke_job(self):
b = job.get_last_build()
while b.is_running():
- time.sleep(0.25)
+ time.sleep(1)
artifacts = b.get_artifact_dict()
self.assertIsInstance(artifacts, dict)
- artifact = artifacts['out.txt']
+ text_artifact = artifacts['out.txt']
+ binary_artifact = artifacts['out.gz']
tempDir = tempfile.mkdtemp()
try:
- artifact.save_to_dir(tempDir)
- readBackText = open(os.path.join(tempDir, artifact.filename), 'rb').read().strip()
+ # Verify that we can handle text artifacts
+ text_artifact.save_to_dir(tempDir)
+ readBackText = open(os.path.join(
+ tempDir, text_artifact.filename), 'rb').read().strip()
+ self.assertTrue(readBackText.startswith('PING localhost'))
+ self.assertTrue(readBackText.endswith('ms'))
+
+ # Verify that we can hande binary artifacts
+ binary_artifact.save_to_dir(tempDir)
+ readBackText = gzip.open(os.path.join(
+ tempDir,
+ binary_artifact.filename,
+ ), 'rb' ).read().strip()
self.assertTrue(readBackText.startswith('PING localhost'))
self.assertTrue(readBackText.endswith('ms'))
finally: