commit message from python script

This commit is contained in:
2023-05-31 20:00:01 +02:00
parent fc98645c0d
commit 3799b24f7e
5 changed files with 87 additions and 6 deletions

View File

@@ -1,6 +1,11 @@
#! /usr/bin/env python3.10
import os
import jenkins, os
import xml.etree.ElementTree as ET
#connect
server = jenkins.Jenkins('https://man-dan-03:9443', username='JonnyBravo', password='113c3449636622439627ab1d51454fc07c')
def show_all_files_directory(dir_path = str, search_endung = False, search_string = False):
li_all = []
@@ -23,10 +28,9 @@ def show_all_directory(dir_path = str, search_endung = False, search_string = Fa
for root_folder, dirs, files in os.walk(dir_path, topdown=False):
for name in dirs:
FullPATH = str(os.path.join(root_folder, name))
if name == search_string:
#print(name)
if not name.find(search_string) == -1:
li_all.append(FullPATH)
print(FullPATH)
return li_all
@@ -39,12 +43,25 @@ def modify_jenkins_configfile(config_file_list = list):
print(line.rstrip("\n"))
print("#" * len(config_file_FullPath))
def added_config_to_jenkins_xml(config_xml = str):
xml_root = ET.parse(config_xml).getroot()
xml_str = ET.tostring(xml_root, encoding='utf8', method='xml').decode()
for strategy in xml_root.findall('sources/data/jenkins.branch.BranchSource'):
value = strategy.get('id')
print(strategy.get('id'))
print(value)
def main():
#test = show_all_files_directory(dir_path=os.sep + "home" + os.sep + "jonnybravo" + os.sep + ".jenkins" + os.sep + "data" + os.sep + "jobs", search_string="config.xml")
test2 = show_all_directory(dir_path=os.sep + "home" + os.sep + "jonnybravo" + os.sep + ".jenkins" + os.sep + "data" + os.sep + "jobs", search_string="ansible_test")
find_folder = show_all_directory(dir_path=os.sep + "home" + os.sep + "jonnybravo" + os.sep + ".jenkins" + os.sep + "data" + os.sep + "jobs", search_string="mulit")
for config_file in find_folder:
file = config_file + os.sep + "config.xml"
print(file)
added_config_to_jenkins_xml(file)
#modify_jenkins_configfile(config_file_list=test)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,20 @@
#!/usr/bin/python
import jenkins
if __name__ == '__main__':
#server = Jenkins('https://man-dan-03:9443', username='JonnyBravo', password='113c3449636622439627ab1d51454fc07c')
server = jenkins.Jenkins('https://man-dan-03:9443', username='JonnyBravo', password='113c3449636622439627ab1d51454fc07c')
job_config = server.get_job_config('mulit_pipeline')
#print(job_config)
#config=job.get_config()
old_config_part = """ <strategy class="jenkins.branch.DefaultBranchPropertyStrategy">
<properties class="empty-list"/>
</strategy>"""
new_config_part = """ <strategy class="jenkins.branch.DefaultBranchPropertyStrategy">
<properties class="-----------------------------------"/>
</strategy>"""
new = job_config.replace(new_config_part, old_config_part)
server.reconfig_job('mulit_pipeline', new)
#new = config.replace('oldvalue', 'newvalue')
#job.update_config(new)