diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index c48d280f6..0da3b57af 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -352,7 +352,7 @@ class Builder(object): self.cache.set(job.name, old_md5) if self.cache.has_changed(job.name, md5) or self.ignore_cache: - self.jenkins.update_job(job.name, job.output()) + self.jenkins.update_job(job.name, job.output().decode('utf-8')) updated_jobs += 1 self.cache.set(job.name, md5) else: diff --git a/tests/cmd/subcommands/test_update.py b/tests/cmd/subcommands/test_update.py index 18b573752..f5ee0c226 100644 --- a/tests/cmd/subcommands/test_update.py +++ b/tests/cmd/subcommands/test_update.py @@ -15,6 +15,7 @@ # under the License. import os +import six from jenkins_jobs import cmd from jenkins_jobs import builder @@ -39,6 +40,26 @@ class UpdateTests(CmdTestsBase): cmd.execute(args, self.config) update_job_mock.assert_called_with([path], []) + @mock.patch('jenkins_jobs.builder.Jenkins.is_job', return_value=True) + @mock.patch('jenkins_jobs.builder.Jenkins.get_jobs') + @mock.patch('jenkins_jobs.builder.Jenkins.get_job_md5') + @mock.patch('jenkins_jobs.builder.Jenkins.update_job') + def test_update_jobs_decode_job_output(self, update_job_mock, + get_job_md5_mock, get_jobs_mock, + is_job_mock): + """ + Test that job xml output has been decoded before attempting to update + """ + # don't care about the value returned here + update_job_mock.return_value = ([], 0) + + path = os.path.join(self.fixtures_path, 'cmd-002.yaml') + args = self.parser.parse_args(['update', path]) + + cmd.execute(args, self.config) + self.assertTrue(isinstance(update_job_mock.call_args[0][1], + six.text_type)) + @mock.patch('jenkins_jobs.builder.Jenkins.is_job', return_value=True) @mock.patch('jenkins_jobs.builder.Jenkins.get_jobs') @mock.patch('jenkins_jobs.builder.Builder.delete_job')