Fix build.get_revision() for GIT repositories
authorSudharshan S <sudharsh@gmail.com>
Tue, 25 Jun 2013 13:32:26 +0000 (19:02 +0530)
committerSudharshan S <sudharsh@gmail.com>
Wed, 26 Jun 2013 09:34:35 +0000 (15:04 +0530)
Filter out actions which are None or not of interest and then extract the git revision from the lastBuiltRevision. Works in cases where branch is of something other than origin/HEAD

jenkinsapi/build.py

index 75074854a53c5eb3901b78a8a34a177f82d52e80..84db7340c51cd280d534ea666109eab44303c5b4 100644 (file)
@@ -53,11 +53,13 @@ class Build(JenkinsBase):
         return maxRevision
 
     def _get_git_rev(self):
-        for item in self._data['actions']:
-            branch = item.get('buildsByBranchName')
-            head = branch and branch.get('origin/HEAD')
-            if head:
-                return head['revision']['SHA1']
+        # Sometimes we have None as part of actions. Filter those actions
+        # which have lastBuiltRevision in them
+        _actions = [x for x in self._data['actions'] if x \
+                        and "lastBuiltRevision" in x]
+        for item in _actions:
+            revision = item["lastBuiltRevision"]["SHA1"]
+            return revision
 
     def _get_hg_rev(self):
         return [x['mercurialNodeName'] for x in self._data['actions'] if 'mercurialNodeName' in x][0]