当前位置: 首页>>代码示例>>Python>>正文


Python Jenkins.get_nodes方法代码示例

本文整理汇总了Python中jenkins.Jenkins.get_nodes方法的典型用法代码示例。如果您正苦于以下问题:Python Jenkins.get_nodes方法的具体用法?Python Jenkins.get_nodes怎么用?Python Jenkins.get_nodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jenkins.Jenkins的用法示例。


在下文中一共展示了Jenkins.get_nodes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from jenkins import Jenkins [as 别名]
# 或者: from jenkins.Jenkins import get_nodes [as 别名]
def main(jenkins_url, user=None, password=None, csv=False):
    """
    NOTE: this is using unauthenticated / anonymous access.
    If that doesn't work for you, change this to something like:
    j = Jenkins(jenkins_url, 'username', 'password')
    """
    if user is not None:
        logger.debug("Connecting to Jenkins as user %s ...", user)
        j = Jenkins(jenkins_url, user, password)
    else:
        logger.debug("Connecting to Jenkins anonymously...")
        j = Jenkins(jenkins_url)
    logger.debug("Connected.")
    labels = {}
    nodes = j.get_nodes()
    for node in nodes:
        try:
            config = j.get_node_config(node['name'])
            logger.debug("got config for node %s", node['name'])
            root = etree.fromstring(config.encode('UTF-8'))
            label = root.xpath('//label')[0].text
            if label is not None and label != '':
                labels[node['name']] = label.split(' ')
        except NotFoundException:
            logger.error("Could not get config for node %s", node['name'])
            continue
    if 'master' in labels:
        tmp = labels['master']
        labels['<master>'] = tmp
    else:
        labels['<master>'] = '<unknown>'
    if not csv:
        print(dict2cols(labels))
        return
    # csv
    for sname, lbls in labels.items():
        print('%s,%s' % (sname, ','.join(lbls)))
开发者ID:jantman,项目名称:misc-scripts,代码行数:39,代码来源:jenkins_node_labels.py


注:本文中的jenkins.Jenkins.get_nodes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。