def _get_build_metadata(self, dir_name, watermark):
        if os.path.exists(os.path.join(dir_name, 'jenkins_build.tar.gz')):
            raise Skip('the build has already been archived', dir_name)
        timestamp = self._timestamp_from_dirname(dir_name)
        # This is not the latest build
        if timestamp is not None and timestamp <= watermark:
            return None
        # Read the build.xml metadata file that Jenkins generates
        build_metadata = os.path.join(dir_name, 'build.xml')

        if not os.access(build_metadata, os.R_OK):
            self.log.debug("Can't read build file at %s" % (build_metadata))
            raise Exception("Can't access build.xml at %s" % (build_metadata))
        else:
            tree = ElementTree()
            tree.parse(build_metadata)
            if timestamp is None:
                try:
                    timestamp = self._timestamp_from_build_file(dir_name, tree)
                    # This is not the latest build
                    if timestamp <= watermark:
                        return None
                except __HOLE__:
                    return None
            keys = ['result', 'number', 'duration']

            kv_pairs = ((k, tree.find(k)) for k in keys)
            d = dict([(k, v.text) for k, v in kv_pairs if v is not None])
            d['timestamp'] = timestamp

            try:
                d['branch'] = tree.find('actions')\
                    .find('hudson.plugins.git.util.BuildData')\
                    .find('buildsByBranchName')\
                    .find('entry')\
                    .find('hudson.plugins.git.util.Build')\
                    .find('revision')\
                    .find('branches')\
                    .find('hudson.plugins.git.Branch')\
                    .find('name')\
                    .text
            except Exception:
                pass
            return d
dataset/ETHPy150Open serverdensity/sd-agent/checks.d/jenkins.py/Jenkins._get_build_metadata