$search
00001 #!/usr/bin/python 00002 00003 00004 # template to create pre-release hudson configuration file 00005 HUDSON_PRERELEASE_CONFIG = """<?xml version='1.0' encoding='UTF-8'?> 00006 <project> 00007 <description>Pre-release build of STACKNAME for ROSDISTRO on UBUNTUDISTRO, ARCH</description> 00008 <logRotator> 00009 <daysToKeep>180</daysToKeep> 00010 <numToKeep>-1</numToKeep> 00011 </logRotator> 00012 <keepDependencies>false</keepDependencies> 00013 <properties> 00014 <hudson.plugins.trac.TracProjectProperty> 00015 <tracWebsite>http://code.ros.org/trac/ros/</tracWebsite> 00016 </hudson.plugins.trac.TracProjectProperty> 00017 </properties> 00018 <scm/> 00019 <assignedNode>prerelease</assignedNode> 00020 <canRoam>false</canRoam> 00021 <disabled>false</disabled> 00022 <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> 00023 <triggers class="vector"/> 00024 <concurrentBuild>false</concurrentBuild> 00025 <builders> 00026 <hudson.tasks.Shell> 00027 <command> 00028 BOOTSTRAP_SCRIPT 00029 rosrun job_generation run_auto_stack_prerelease.py STACKARGS --rosdistro ROSDISTRO --repeat REPEAT SOURCE_ONLY 00030 SHUTDOWN_SCRIPT 00031 </command> 00032 </hudson.tasks.Shell> 00033 </builders> 00034 <publishers> 00035 <hudson.tasks.junit.JUnitResultArchiver> 00036 <testResults>test_results/**/_hudson/*.xml</testResults> 00037 <keepLongStdio>false</keepLongStdio> 00038 <testDataPublishers/> 00039 </hudson.tasks.junit.JUnitResultArchiver> 00040 <hudson.plugins.emailext.ExtendedEmailPublisher> 00041 <recipientList>EMAIL,rosrelease-prerelease@kforge.ros.org</recipientList> 00042 <configuredTriggers> 00043 EMAIL_TRIGGERS 00044 </configuredTriggers> 00045 <defaultSubject>$DEFAULT_SUBJECT</defaultSubject> 00046 <defaultContent>$DEFAULT_CONTENT
 00047 
 00048 <% 
 00049 def ws = build.getParent().getWorkspace()
 00050 def computer = build.getExecutor().getOwner()
 00051 def build_failures = hudson.util.RemotingDiagnostics.executeGroovy("new File(\"${ws}/build_output/buildfailures.txt\").text",computer.getChannel())
 00052 println "${build_failures}"
 00053 def test_failures = hudson.util.RemotingDiagnostics.executeGroovy("new File(\"${ws}/test_output/testfailures.txt\").text",computer.getChannel())
 00054 println "${test_failures}"
 00055 def build_failures_context = hudson.util.RemotingDiagnostics.executeGroovy("new File(\"${ws}/build_output/buildfailures-with-context.txt\").text",computer.getChannel())
 00056 println "${build_failures_context}"
 00057 %></defaultContent> 00058 <defaultContentTypeHTML>false</defaultContentTypeHTML> 00059 <defaultContentIsScript>true</defaultContentIsScript> 00060 </hudson.plugins.emailext.ExtendedEmailPublisher> 00061 </publishers> 00062 <buildWrappers/> 00063 </project> 00064 """ 00065 00066 import roslib; roslib.load_manifest("job_generation") 00067 import rosdistro 00068 from job_generation.jobs_common import * 00069 import hudson 00070 import urllib 00071 import optparse 00072 00073 00074 def prerelease_job_name(rosdistro, stack_list, ubuntu, arch): 00075 return get_job_name('prerelease', rosdistro, '_'.join(stack_list), ubuntu, arch) 00076 00077 00078 def create_prerelease_configs(rosdistro, stack_list, email, repeat, source_only, arches=None, ubuntudistros=None): 00079 stack_list.sort() 00080 00081 if not arches: 00082 arches = ARCHES 00083 if not ubuntudistros: 00084 ubuntudistros = UBUNTU_DISTRO_MAP[rosdistro] 00085 00086 # create hudson config files for each ubuntu distro 00087 configs = {} 00088 for ubuntudistro in ubuntudistros: 00089 for arch in arches: 00090 name = prerelease_job_name(rosdistro, stack_list, ubuntudistro, arch) 00091 hudson_config = HUDSON_PRERELEASE_CONFIG 00092 hudson_config = hudson_config.replace('BOOTSTRAP_SCRIPT', BOOTSTRAP_SCRIPT) 00093 hudson_config = hudson_config.replace('SHUTDOWN_SCRIPT', SHUTDOWN_SCRIPT) 00094 hudson_config = hudson_config.replace('EMAIL_TRIGGERS', get_email_triggers(['Unstable', 'Failure', 'StillFailing', 'Fixed', 'StillUnstable', 'Success'], False)) 00095 hudson_config = hudson_config.replace('UBUNTUDISTRO', ubuntudistro) 00096 hudson_config = hudson_config.replace('ARCH', arch) 00097 hudson_config = hudson_config.replace('ROSDISTRO', rosdistro) 00098 hudson_config = hudson_config.replace('STACKNAME', '---'.join(stack_list)) 00099 hudson_config = hudson_config.replace('STACKARGS', ' '.join(['--stack %s'%s for s in stack_list])) 00100 hudson_config = hudson_config.replace('EMAIL', email) 00101 hudson_config = hudson_config.replace('REPEAT', str(repeat)) 00102 if source_only: 00103 hudson_config = hudson_config.replace('SOURCE_ONLY', '--source-only') 00104 else: 00105 hudson_config = hudson_config.replace('SOURCE_ONLY', '') 00106 configs[name] = hudson_config 00107 return configs 00108 00109 00110 00111 def main(): 00112 (options, args) = get_options(['stack', 'rosdistro', 'email'], ['repeat', 'source-only', 'arch', 'ubuntu', 'delete']) 00113 if not options: 00114 return -1 00115 00116 try: 00117 # create hudson instance 00118 if len(args) == 2: 00119 hudson_instance = hudson.Hudson(SERVER, args[0], args[1]) 00120 else: 00121 info = urllib.urlopen(CONFIG_PATH).read().split(',') 00122 hudson_instance = hudson.Hudson(SERVER, info[0], info[1]) 00123 prerelease_configs = create_prerelease_configs(options.rosdistro, options.stack, options.email, options.repeat, options.source_only, options.arch, options.ubuntu) 00124 00125 # check if jobs are not already running 00126 for job_name in prerelease_configs: 00127 exists = hudson_instance.job_exists(job_name) 00128 if exists and hudson_instance.job_is_running(job_name): 00129 print 'Cannot create job %s because a job with the same name is already running.'%job_name 00130 print 'Please try again when this job finished running.' 00131 return 00132 00133 # send prerelease tests to Hudson 00134 print 'Creating pre-release Hudson jobs:' 00135 schedule_jobs(prerelease_configs, start=True, hudson_obj=hudson_instance, delete=options.delete) 00136 if options.delete: 00137 print 'Jobs have been deleted. You can now start new jobs' 00138 else: 00139 print 'You will receive %d emails on %s, one for each job'%(len(prerelease_configs), options.email) 00140 print 'You can follow the progress of these jobs on <%s/view/pre-release>'%(SERVER) 00141 00142 # catch all exceptions 00143 except Exception, e: 00144 print 'ERROR: Failed to communicate with Hudson server. Try again later.' 00145 00146 00147 if __name__ == '__main__': 00148 main() 00149 00150 00151 00152