0

我有 Jenkins 和 python,还有一些工作在队列中。我有一个脚本

import jenkins 
j = jenkins.Jenkins('http:///', '....', '.......')
queue_info = j.get_queue_info()
print(queue_info)

此命令给我以下输出:

[{u'task': {u'url': u'http://', u'color': u'aborted', u'name': u'f1111111111'}, u'stuck': False, u'url': 
u'queue/item/37/', u'inQueueSince': 1397554800875L, u'actions': [{u'causes': [{u'userName': u'admin', u'userId': u'admin', u'shortDescription':
u'Started by user admin'}]}], u'why': u'Waiting for next available executor on NO_1', u'buildable': True, u'params': u'', u'buildableStartMilliseconds': 1397554800878L, u'id': 37, u'pending': False, u'blocked': False}

如何获取 u'name' 的名称并将其变为 python 中的动态海量

4

1 回答 1

1

输出是一个字典列表,因此您可以简单地访问列表中的第一个条目并使用字典的键。

让我们从在这里定义一个函数开始:

import subprocess as sp

''' Runs a program '''
def run(prog):
      print("Lets run program %s" % prog)
      sp.Popen([prog], stdout=sp.STDOUT, stderr=sp.STDOUT)

      # This makes the script wait until the end of the program
      sp.wait()

然后,在 for 循环中,你只需要调用 run 函数:

for n in queue_info:
      run(n['task']['name'])
于 2014-04-15T09:59:59.817 回答