diff --git a/jenkinsapi/build.py b/jenkinsapi/build.py index 3fbb51b9..b0e034da 100644 --- a/jenkinsapi/build.py +++ b/jenkinsapi/build.py @@ -82,18 +82,30 @@ def get_slave(self): return self._data["builtOn"] def get_revision(self): - change_sets = self._data['changeSets'] - vcs = change_sets[0]['kind'] if change_sets else 'git' + if 'changeSet' in self._data: + vcs = self._data['changeSet']['kind'] or 'git' + elif 'changeSets' in self._data and self._data['changeSets']: + vcs = self._data['changeSets'][0]['kind'] or 'git' + else: + vcs = 'git' return getattr(self, '_get_%s_rev' % vcs, lambda: None)() def get_revision_branch(self): - change_sets = self._data['changeSets'] - vcs = change_sets[0]['kind'] if change_sets else 'git' + if 'changeSet' in self._data: + vcs = self._data['changeSet']['kind'] or 'git' + elif 'changeSets' in self._data and self._data['changeSets']: + vcs = self._data['changeSets'][0]['kind'] or 'git' + else: + vcs = 'git' return getattr(self, '_get_%s_rev_branch' % vcs, lambda: None)() def get_repo_url(self): - change_sets = self._data['changeSets'] - vcs = change_sets[0]['kind'] if change_sets else 'git' + if 'changeSet' in self._data: + vcs = self._data['changeSet']['kind'] or 'git' + elif 'changeSets' in self._data and self._data['changeSets']: + vcs = self._data['changeSets'][0]['kind'] or 'git' + else: + vcs = 'git' return getattr(self, '_get_%s_repo_url' % vcs, lambda: None)() def get_params(self): @@ -143,13 +155,11 @@ def get_changeset_items(self): } """ if 'changeSet' in self._data: - for i in self._data['changeSet']: - if 'items' in i: - return i['items'] + if 'items' in self._data['changeSet']: + return self._data['changeSet']['items'] elif 'changeSets' in self._data: - for i in self._data['changeSets']: - if 'items' in i: - return i['items'] + if 'items' in self._data['changeSets']: + return self._data['changeSets']['items'] return [] def _get_svn_rev(self): @@ -165,10 +175,10 @@ def _get_git_rev(self): # 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 "build" in x] + if x and "lastBuiltRevision" in x] if _actions: - return _actions[0]["build"]["revision"]["SHA1"] + return _actions[0]["lastBuiltRevision"]["SHA1"] return None @@ -186,9 +196,9 @@ def _get_git_rev_branch(self): # 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 "build" in x] + if x and "lastBuiltRevision" in x] - return _actions[0]["build"]["revision"]["branch"][0]["name"] + return _actions[0]["lastBuiltRevision"]["branch"] def _get_hg_rev_branch(self): raise NotImplementedError('_get_hg_rev_branch is not yet implemented')