00001
00002 import random
00003
00004
00005 HUDSON_POST_RELEASE_CONFIG = """<?xml version='1.0' encoding='UTF-8'?>
00006 <project>
00007 <description>Build of STACKNAME post-release 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 HUDSON_VCS
00019 <assignedNode>released</assignedNode>
00020 <canRoam>false</canRoam>
00021 <disabled>false</disabled>
00022 <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
00023 <triggers class="vector">
00024 <hudson.triggers.SCMTrigger>
00025 <spec>TIME_TRIGGER</spec>
00026 </hudson.triggers.SCMTrigger>
00027 </triggers>
00028 <concurrentBuild>false</concurrentBuild>
00029 <builders>
00030 <hudson.tasks.Shell>
00031 <command>
00032 BOOTSTRAP_SCRIPT
00033 rosrun job_generation run_auto_stack_postrelease.py --stack STACKNAME --rosdistro ROSDISTRO
00034 SHUTDOWN_SCRIPT
00035 </command>
00036 </hudson.tasks.Shell>
00037 </builders>
00038 <publishers>
00039 <hudson.tasks.BuildTrigger>
00040 <childProjects>JOB_CHILDREN</childProjects>
00041 <threshold>
00042 <name>SUCCESS</name>
00043 <ordinal>0</ordinal>
00044 <color>BLUE</color>
00045 </threshold>
00046 </hudson.tasks.BuildTrigger>
00047 <hudson.tasks.junit.JUnitResultArchiver>
00048 <testResults>test_results/**/_hudson/*.xml</testResults>
00049 </hudson.tasks.junit.JUnitResultArchiver>
00050 <hudson.plugins.emailext.ExtendedEmailPublisher>
00051 <recipientList>EMAIL</recipientList>
00052 <configuredTriggers>
00053 EMAIL_TRIGGERS
00054 </configuredTriggers>
00055 <defaultSubject>$DEFAULT_SUBJECT</defaultSubject>
00056 <defaultContent>$DEFAULT_CONTENT
00057 
00058 <% 
00059 def ws = build.getParent().getWorkspace()
00060 def computer = build.getExecutor().getOwner()
00061 def build_failures = hudson.util.RemotingDiagnostics.executeGroovy("new File(\"${ws}/build_output/buildfailures.txt\").text",computer.getChannel())
00062 println "${build_failures}"
00063 def test_failures = hudson.util.RemotingDiagnostics.executeGroovy("new File(\"${ws}/test_output/testfailures.txt\").text",computer.getChannel())
00064 println "${test_failures}"
00065 def build_failures_context = hudson.util.RemotingDiagnostics.executeGroovy("new File(\"${ws}/build_output/buildfailures-with-context.txt\").text",computer.getChannel())
00066 println "${build_failures_context}"
00067 %></defaultContent>
00068 <defaultContentTypeHTML>false</defaultContentTypeHTML>
00069 <defaultContentIsScript>true</defaultContentIsScript>
00070 </hudson.plugins.emailext.ExtendedEmailPublisher>
00071 </publishers>
00072 <buildWrappers/>
00073 </project>
00074 """
00075
00076
00077 import roslib; roslib.load_manifest("job_generation")
00078 import rosdistro
00079 import time
00080 from job_generation.jobs_common import *
00081 import urllib
00082 import optparse
00083
00084
00085 def post_release_job_name(rosdistro, stack_name, ubuntu, arch):
00086 return get_job_name('released', rosdistro, stack_name, ubuntu, arch)
00087
00088
00089 def create_post_release_configs(rosdistro, stack):
00090
00091 gold_job = post_release_job_name(rosdistro, stack.name, UBUNTU_DISTRO_MAP[rosdistro][0], ARCHES[0])
00092 gold_children = [post_release_job_name(rosdistro, stack.name, u, a)
00093 for a in ARCHES for u in UBUNTU_DISTRO_MAP[rosdistro]]
00094 gold_children.remove(gold_job)
00095
00096
00097 configs = {}
00098 for ubuntudistro in UBUNTU_DISTRO_MAP[rosdistro]:
00099 for arch in ARCHES:
00100 name = post_release_job_name(rosdistro, stack.name, ubuntudistro, arch)
00101
00102
00103 if stack.vcs_config.type in hudson_scm_managers:
00104 hudson_vcs = hudson_scm_managers[stack.vcs_config.type]
00105 else:
00106 raise NotImplementedError("vcs type %s not implemented as hudson scm manager"%stack.vcs_config.type)
00107
00108
00109 if stack.vcs_config.type in ['svn']:
00110 hudson_vcs = hudson_vcs.replace('STACKNAME', stack.name)
00111 hudson_vcs = hudson_vcs.replace('STACKURI', stack.vcs_config.anon_distro_tag)
00112 elif stack.vcs_config.type in ['git', 'hg', 'bzr']:
00113 hudson_vcs = hudson_vcs.replace('STACKBRANCH', stack.vcs_config.distro_tag)
00114 hudson_vcs = hudson_vcs.replace('STACKURI', stack.vcs_config.anon_repo_uri)
00115 hudson_vcs = hudson_vcs.replace('STACKNAME', stack.name)
00116 else:
00117 print "UNSUPPORTED VCS TYPE"
00118 raise
00119
00120
00121 time_trigger = ''
00122 job_children = ''
00123 if name == gold_job:
00124
00125 time_trigger = '%d %d * * *'%(int(50*random.random()), int(4*random.random()))
00126 job_children = ', '.join(gold_children)
00127 hudson_config = HUDSON_POST_RELEASE_CONFIG
00128 hudson_config = hudson_config.replace('BOOTSTRAP_SCRIPT', BOOTSTRAP_SCRIPT)
00129 hudson_config = hudson_config.replace('SHUTDOWN_SCRIPT', SHUTDOWN_SCRIPT)
00130 hudson_config = hudson_config.replace('EMAIL_TRIGGERS', get_email_triggers(['Unstable', 'Failure', 'Fixed']))
00131 hudson_config = hudson_config.replace('UBUNTUDISTRO', ubuntudistro)
00132 hudson_config = hudson_config.replace('ARCH', arch)
00133 hudson_config = hudson_config.replace('ROSDISTRO', rosdistro)
00134 hudson_config = hudson_config.replace('STACKNAME', stack.name)
00135 hudson_config = hudson_config.replace('HUDSON_VCS', hudson_vcs)
00136 hudson_config = hudson_config.replace('TIME_TRIGGER', time_trigger)
00137 hudson_config = hudson_config.replace('JOB_CHILDREN', job_children)
00138 hudson_config = hudson_config.replace('EMAIL', 'wim+released@willowgarage.com')
00139 configs[name] = hudson_config
00140 return configs
00141
00142
00143
00144
00145 def main():
00146 (options, args) = get_options(['rosdistro'], ['delete', 'wait', 'stack'])
00147 if not options:
00148 return -1
00149
00150
00151 distro_obj = rosdistro.Distro(get_rosdistro_file(options.rosdistro))
00152 print 'Operating on ROS distro %s'%distro_obj.release_name
00153
00154
00155 post_release_configs = {}
00156 if options.stack:
00157 stack_list = options.stack
00158 else:
00159 stack_list = distro_obj.released_stacks
00160 for stack_name in stack_list:
00161 post_release_configs.update(create_post_release_configs(distro_obj.release_name, distro_obj.released_stacks[stack_name]))
00162
00163
00164
00165 schedule_jobs(post_release_configs, options.wait, options.delete)
00166
00167
00168 if __name__ == '__main__':
00169 main()
00170
00171
00172
00173