Merge lp:~fginther/jenkins-launchpad-plugin/jenkins-token into lp:~private-ps-quality-team/jenkins-launchpad-plugin/trunk

Proposed by Francis Ginther
Status: Merged
Approved by: Francis Ginther
Approved revision: 124
Merged at revision: 124
Proposed branch: lp:~fginther/jenkins-launchpad-plugin/jenkins-token
Merge into: lp:~private-ps-quality-team/jenkins-launchpad-plugin/trunk
Diff against target: 81 lines (+41/-3)
3 files modified
jlp.config (+3/-0)
jlp/jenkinsutils.py (+4/-2)
tests/test_jenkinsutils.py (+34/-1)
To merge this branch: bzr merge lp:~fginther/jenkins-launchpad-plugin/jenkins-token
Reviewer Review Type Date Requested Status
Vincent Ladeuil (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+196396@code.launchpad.net

Commit message

Add a jenkins_build_token config parameter to allow triggering of jenkins jobs through the script trigger on newer versions of jenkins.

Description of the change

Add a jenkins_build_token config parameter to allow triggering of jenkins jobs through the script trigger on newer versions of jenkins.

To post a comment you must log in.
124. By Francis Ginther

Fix pep8 error.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Vincent Ladeuil (vila) wrote :

Nice ! Cover letter + tests make reviews easy \o/

Only a few style suggestions if you care about them:

47 + '''Verify that the default jenkins_build_token value results in a
48 + token parameter of None being passed to jenkins.build_job API.'''

Test docstrings are used by some test runners under the assumption that the first line is short enough (<80 chars) and can be used to document the test purpose.

You can give a longer description when needed after an empty line.

I.e.:

'''No token sent if empty.

Verify that the default jenkins_build_token value results in a
token parameter of None being passed to jenkins.build_job API.
'''

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'jlp.config'
--- jlp.config 2013-05-31 07:26:58 +0000
+++ jlp.config 2013-11-22 21:56:48 +0000
@@ -25,6 +25,9 @@
25#URL of your jenkins.25#URL of your jenkins.
26jenkins_url: http://localhost:8080/26jenkins_url: http://localhost:8080/
2727
28#Token to pass when triggering a jenkins build (leave blank for none)
29jenkins_build_token:
30
28# console output from the following jobs will not be printed to the31# console output from the following jobs will not be printed to the
29# affected merge proposal (in the "Executed test runs:" section)32# affected merge proposal (in the "Executed test runs:" section)
30jobs_blacklisted_from_messages: [generic-land, generic-update_mp, generic-release-land, generic-mediumtests-builder, generic-mediumtests]33jobs_blacklisted_from_messages: [generic-land, generic-update_mp, generic-release-land, generic-mediumtests-builder, generic-mediumtests]
3134
=== modified file 'jlp/jenkinsutils.py'
--- jlp/jenkinsutils.py 2013-11-19 00:11:18 +0000
+++ jlp/jenkinsutils.py 2013-11-22 21:56:48 +0000
@@ -668,8 +668,10 @@
668 logger.debug('Doing a regular build')668 logger.debug('Doing a regular build')
669669
670 try:670 try:
671 logger.debug('Starting job: ' + str(jenkins_params))671 logger.debug('Starting job (%s): %s' %
672 j.build_job(jenkins_job, jenkins_params)672 (jenkins_job, str(jenkins_params)))
673 build_token = get_config_option('jenkins_build_token')
674 j.build_job(jenkins_job, jenkins_params, build_token)
673 except jenkins.JenkinsException:675 except jenkins.JenkinsException:
674 logger.debug('Starting a job failed')676 logger.debug('Starting a job failed')
675 message = "ERROR: failed to start a jenkins job"677 message = "ERROR: failed to start a jenkins job"
676678
=== modified file 'tests/test_jenkinsutils.py'
--- tests/test_jenkinsutils.py 2013-10-09 19:43:05 +0000
+++ tests/test_jenkinsutils.py 2013-11-22 21:56:48 +0000
@@ -1,5 +1,5 @@
1from mock import MagicMock, patch1from mock import MagicMock, patch
2from jlp import jenkinsutils, launchpadutils2from jlp import jenkinsutils, launchpadutils, _config
3import unittest3import unittest
4from tests import JenkinsJSONData4from tests import JenkinsJSONData
5from jlp import get_config_option5from jlp import get_config_option
@@ -1002,6 +1002,39 @@
1002 self.assertEqual(j.build_job.call_count, 1)1002 self.assertEqual(j.build_job.call_count, 1)
1003 self.assertEqual(j.build_job.call_args[0][0], 'jenkins_job')1003 self.assertEqual(j.build_job.call_args[0][0], 'jenkins_job')
10041004
1005 def test_start_jenkins_job_with_jenkins_build_token_none(self):
1006 '''Verify that the default jenkins_build_token value results in a
1007 token parameter of None being passed to jenkins.build_job API.'''
1008 mp = MagicMock()
1009 mp.web_link = 'http://my-example-url.com'
1010 j = MagicMock()
1011 j.get_job_info = MagicMock(return_value={'buildable': True})
1012 j.build_job = MagicMock()
1013 jenkins = MagicMock()
1014 jenkins.Jenkins = MagicMock(return_value=j)
1015 with patch('jlp.jenkinsutils.jenkins', new=jenkins):
1016 jenkinsutils.start_jenkins_job(self.launchpad_user, 'url',
1017 'jenkins_job', mp)
1018 self.assertEqual(j.build_job.call_args[0][2], None)
1019
1020 def test_start_jenkins_job_with_jenkins_build_token_set(self):
1021 '''Verify that when jenkins_build_token value is set, the
1022 jenkins.build_job API is called with the specified token.'''
1023 mp = MagicMock()
1024 mp.web_link = 'http://my-example-url.com'
1025 j = MagicMock()
1026 j.get_job_info = MagicMock(return_value={'buildable': True})
1027 j.build_job = MagicMock()
1028 jenkins = MagicMock()
1029 token = 'JENKINS_BUILD_TOKEN'
1030 # Override the default value with the specific token
1031 _config['jenkins_build_token'] = token
1032 jenkins.Jenkins = MagicMock(return_value=j)
1033 with patch('jlp.jenkinsutils.jenkins', new=jenkins):
1034 jenkinsutils.start_jenkins_job(self.launchpad_user, 'url',
1035 'jenkins_job', mp)
1036 self.assertEqual(j.build_job.call_args[0][2], token)
1037
10051038
1006class TestGetResultLine(TestWithScenarios):1039class TestGetResultLine(TestWithScenarios):
1007 scenarios = [1040 scenarios = [

Subscribers

People subscribed via source and target branches

to all changes: