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
1=== modified file 'jlp.config'
2--- jlp.config 2013-05-31 07:26:58 +0000
3+++ jlp.config 2013-11-22 21:56:48 +0000
4@@ -25,6 +25,9 @@
5 #URL of your jenkins.
6 jenkins_url: http://localhost:8080/
7
8+#Token to pass when triggering a jenkins build (leave blank for none)
9+jenkins_build_token:
10+
11 # console output from the following jobs will not be printed to the
12 # affected merge proposal (in the "Executed test runs:" section)
13 jobs_blacklisted_from_messages: [generic-land, generic-update_mp, generic-release-land, generic-mediumtests-builder, generic-mediumtests]
14
15=== modified file 'jlp/jenkinsutils.py'
16--- jlp/jenkinsutils.py 2013-11-19 00:11:18 +0000
17+++ jlp/jenkinsutils.py 2013-11-22 21:56:48 +0000
18@@ -668,8 +668,10 @@
19 logger.debug('Doing a regular build')
20
21 try:
22- logger.debug('Starting job: ' + str(jenkins_params))
23- j.build_job(jenkins_job, jenkins_params)
24+ logger.debug('Starting job (%s): %s' %
25+ (jenkins_job, str(jenkins_params)))
26+ build_token = get_config_option('jenkins_build_token')
27+ j.build_job(jenkins_job, jenkins_params, build_token)
28 except jenkins.JenkinsException:
29 logger.debug('Starting a job failed')
30 message = "ERROR: failed to start a jenkins job"
31
32=== modified file 'tests/test_jenkinsutils.py'
33--- tests/test_jenkinsutils.py 2013-10-09 19:43:05 +0000
34+++ tests/test_jenkinsutils.py 2013-11-22 21:56:48 +0000
35@@ -1,5 +1,5 @@
36 from mock import MagicMock, patch
37-from jlp import jenkinsutils, launchpadutils
38+from jlp import jenkinsutils, launchpadutils, _config
39 import unittest
40 from tests import JenkinsJSONData
41 from jlp import get_config_option
42@@ -1002,6 +1002,39 @@
43 self.assertEqual(j.build_job.call_count, 1)
44 self.assertEqual(j.build_job.call_args[0][0], 'jenkins_job')
45
46+ def test_start_jenkins_job_with_jenkins_build_token_none(self):
47+ '''Verify that the default jenkins_build_token value results in a
48+ token parameter of None being passed to jenkins.build_job API.'''
49+ mp = MagicMock()
50+ mp.web_link = 'http://my-example-url.com'
51+ j = MagicMock()
52+ j.get_job_info = MagicMock(return_value={'buildable': True})
53+ j.build_job = MagicMock()
54+ jenkins = MagicMock()
55+ jenkins.Jenkins = MagicMock(return_value=j)
56+ with patch('jlp.jenkinsutils.jenkins', new=jenkins):
57+ jenkinsutils.start_jenkins_job(self.launchpad_user, 'url',
58+ 'jenkins_job', mp)
59+ self.assertEqual(j.build_job.call_args[0][2], None)
60+
61+ def test_start_jenkins_job_with_jenkins_build_token_set(self):
62+ '''Verify that when jenkins_build_token value is set, the
63+ jenkins.build_job API is called with the specified token.'''
64+ mp = MagicMock()
65+ mp.web_link = 'http://my-example-url.com'
66+ j = MagicMock()
67+ j.get_job_info = MagicMock(return_value={'buildable': True})
68+ j.build_job = MagicMock()
69+ jenkins = MagicMock()
70+ token = 'JENKINS_BUILD_TOKEN'
71+ # Override the default value with the specific token
72+ _config['jenkins_build_token'] = token
73+ jenkins.Jenkins = MagicMock(return_value=j)
74+ with patch('jlp.jenkinsutils.jenkins', new=jenkins):
75+ jenkinsutils.start_jenkins_job(self.launchpad_user, 'url',
76+ 'jenkins_job', mp)
77+ self.assertEqual(j.build_job.call_args[0][2], token)
78+
79
80 class TestGetResultLine(TestWithScenarios):
81 scenarios = [

Subscribers

People subscribed via source and target branches

to all changes: