Trigger parameterized builds with token as well
authorRamon van Alteren <ramon@vanalteren.nl>
Mon, 6 Feb 2012 08:29:04 +0000 (09:29 +0100)
committerRamon van Alteren <ramon@vanalteren.nl>
Wed, 8 Feb 2012 14:11:26 +0000 (15:11 +0100)
Per request of RBURHUM.
Although the api explaination recommends to use authentification / security to trigger builds and not
use the (deprecated) trigger builds remotely with a security token, apparently people are still using it.

jenkinsapi/job.py

index 5447548..7adb480 100644 (file)
@@ -34,11 +34,13 @@ class Job(JenkinsBase):
     def get_build_triggerurl( self, token=None, params={} ):
         if token is None:
             extra = "build"
+        elif params:
+            assert isinstance(token, str ), "token if provided should be a string."
+            params['token'] = token
+            extra = "buildWithParameters?" + urllib.urlencode(params)
         else:
             assert isinstance(token, str ), "token if provided should be a string."
             extra = "build?" + urllib.urlencode({'token':token})
-        if params:
-            extra = "buildWithParameters?" + urllib.urlencode(params)
         buildurl = urlparse.urljoin( self.baseurl, extra )
         return buildurl