我是python的新手,
下面是用于触发Jenkins项目的python脚本。
'''subprocess for triggering jenkins'''
print("Update Started 2.........subprocess for triggering jenkins.")
#cmd2 = ['curl', c3]
mycmd = r'start chrome/new-tab {}'.format(c3)
n2=subprocess.Popen(mycmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
#wait for the process to terminate
#out, err = n2.communicate()
#errcode = n2.returncode
'''wait until trigger the jenkins'''
print("Wait until trigger the jenkins..................")
# Deadlock is happening here.
n2.wait()
print("Wait done.......................................")
它没有触发项目,
但是,当我尝试以Debug方式进行调试时-n2.wait()
下面是脚本的日志:
Update Started 2.........subprocess for triggering jenkins.
Wait until trigger jenkins..................
更新1: 当我尝试通过修改..
n2.wait(10)
下面是控制台打印的数据。
Traceback (most recent call last):
File "C:/Users/adevaraj/Desktop/Jenkins_CVS_Testing_Apr/CVS_LOG_Compare.py", line 189, in <module>
n2.wait(10)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 1057, in wait
raise TimeoutExpired(self.args, timeout)
subprocess.TimeoutExpired: Command 'start chrome/new-tab http://localhost:8080/job/P16G0804_GM_A2XX_PSS/build?token=A2XX' timed out after 10 seconds
更新2: 网址正在从Excel工作表中获取(该代码未在此处发布)
更新3:
在此代码中,c3是来自后端的触发器的网址
有人可以帮我吗?
答案 0 :(得分:0)
我假设您想触发 Jenkins 构建。只需使用 Jenkins REST API怎么样?
import requests
url = "http://localhost:8080/job/P16G0804_GM_A2XX_PSS/buildWithParameters?
arg1=val1&arg2=val2"
response = requests.get(url)
print(response)
希望对您有帮助!