python-jenkins 自动化实践(UI 和 API 自动化 混合应用)
2021-03-27 03:26
标签:mit 名称 odi yaml range drive obj sub turn *# -- coding: utf-8 -*- import jenkins def GetYaml(): def linkJenkins(): def CheckBranch(server): def SetBranch(): def SetMaster(): JenkinsBranch.yaml Server: if name == "main": python-jenkins 自动化实践(UI 和 API 自动化 混合应用) 标签:mit 名称 odi yaml range drive obj sub turn 原文地址:https://blog.51cto.com/14103476/2533677
import re
yamlPath = os.path.join(os.getcwd(),"JenkinsBranch.yaml")
f = open(yamlPath,‘r‘,encoding=‘utf-8‘)
yamldata = yaml.load(f.read())
return yamldata
jenkins_server_url = ‘http://jenkins.test***.cn/jenkins/‘
server = jenkins.Jenkins(jenkins_server_url,username=userName,password=password)
return server
jobsLen = len(server.get_jobs())
list1 = []
list2 = []for i in range(jobsLen):
# print(server.get_jobs()[i][‘name‘])
matchObj = re.findall(re.compile(r‘
yamlData = GetYaml()
jenkins_server_url = yamlData[‘Jenkins‘][‘url‘]
userName = yamlData[‘Jenkins‘][‘username‘]
password = yamlData[‘Jenkins‘][‘password‘]driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(10)
driver.get(jenkins_server_url)
driver.find_element_by_id("j_username").send_keys(userName)
driver.find_element_by_name("j_password").send_keys(password)
driver.find_element_by_id("yui-gen1-button").click()
server = linkJenkins()
jobsLen = len(server.get_jobs())
mustBuildJob = GetYaml()[‘Server‘]
for i in range(jobsLen):
jobName = server.get_jobs()[i][‘name‘]
for key in mustBuildJob:
if jobName == key:
driver.get(jenkins_server_url + "job/" + key + "/configure")
branchKey = driver.find_element_by_xpath(‘//*[@id="main-panel"]/div/div/div/form/***/input‘)
** # print(branchKey.get_attribute(‘value‘))**
branchKey.clear()
branchKey.send_keys("*/" + str(mustBuildJob[key]))
time.sleep(2)
driver.find_element_by_name(‘Submit‘).click()
time.sleep(2)
server.build_job(jobName)
yamlData = GetYaml()
jenkins_server_url = yamlData[‘Jenkins‘][‘url‘]
userName = yamlData[‘Jenkins‘][‘username‘]
password = yamlData[‘Jenkins‘][‘password‘]driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(10)
driver.get(jenkins_server_url)
driver.find_element_by_id("j_username").send_keys(userName)
driver.find_element_by_name("j_password").send_keys(password)
driver.find_element_by_id("yui-gen1-button").click()
server = linkJenkins()
jobsLen = len(server.get_jobs())
for i in range(jobsLen):
driver.get(jenkins_server_url + "job/" + server.get_jobs()[i][‘name‘] + "/configure")
branchKey = driver.find_element_by_xpath(‘//*[@id="main-panel"]/div/div/div/form/table/tbody***/input‘)
branch = branchKey.get_attribute(‘value‘).split(‘/‘)[1]
if branch != ‘master‘:
branchKey.clear()
branchKey.send_keys("*/master")
time.sleep(1)
driver.find_element_by_name(‘Submit‘).click()
server.build_job(server.get_jobs()[i][‘name‘])
Jenkins:
url: http://jenkins.test.***.cn/jenkins/
username: 123.gean
password: 123654
api-invoice: master
api-sms: master link = linkJenkins()
CheckBranch(link)
SetBranch()
SetMaster()
文章标题:python-jenkins 自动化实践(UI 和 API 自动化 混合应用)
文章链接:http://soscw.com/index.php/essay/68400.html