From ed8bc87ff7a24251233347cfbb917b05be2a0a74 Mon Sep 17 00:00:00 2001 From: Sudharshan S Date: Tue, 25 Jun 2013 19:02:26 +0530 Subject: [PATCH] Fix build.get_revision() for GIT repositories 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 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/jenkinsapi/build.py b/jenkinsapi/build.py index 7507485..84db734 100644 --- a/jenkinsapi/build.py +++ b/jenkinsapi/build.py @@ -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] -- 2.34.1