Exemplo n.º 1
0
	def executeWithArgs( self, timeout = 24 * 60 * 60, args = None, captureOutput = False ):
		cmd = [ sys.executable, os.path.abspath( self.getBuildScript() ) ]
		if args:
			cmd.extend( args )
		mApp().message( self, 'invoking build script: {0}'.format( ' '.join( cmd ) ) )
		runner = RunCommand( cmd, timeoutSeconds = timeout, captureOutput = captureOutput )
		with EnvironmentSaver():
			extend_debug_prefix( 'script>' )
			runner.run()
		mApp().debugN( self, 2, 'build script finished, return code is {0}.'.format( runner.getReturnCode() ) )
		return runner
Exemplo n.º 2
0
	def execute( self ):
		"""This is the main driver method when the control process is run as the master.
		In an endless loop, it invokes itself in slave mode to perform all builds that have accumulated since the last start.
		After every run, the master takes a short sleep."""
		# execute the build control process slave:
		cmd = '{0} {1}'.format( sys.executable, ' '.join( sys.argv + [ '--slave' ] ) )
		self.debug( self, '*** now starting slave CI process: {0} ***'.format( cmd ) )
		oldIndent = extend_debug_prefix( 'slave' )
		result = -1
		try:
			result = os.system( cmd ) # do not use RunCommand, it catches the output
		finally:
			restore_debug_prefix( oldIndent )
		self.debug( self, '*** slave finished with exit code {0}. ***'.format( result ) )
Exemplo n.º 3
0
	def performBuild( self, buildInfo ):
		"""Start a build process for a new revision. baseDir is the directory where all builds go. To build 
		different revisions and build types under it, subdirectories have to be used."""
		buildType = buildInfo.getBuildType().lower()
		# Under windows we have the problem that paths need to be short, so take only 7 digists of the git hash
		# this is also done for svn revision numbers, but these should not be so long
		if sys.platform == 'win32':
			rev = buildInfo.getRevision()[0:7]
		else:
			rev = buildInfo.getRevision()
		name = make_foldername_from_string( buildInfo.getProjectName() )
		# find suitable names for the different build dirs:
		baseDir = os.path.join( os.getcwd(), 'builds' )
		buildRoot = mApp().getSettings().get( Settings.SimpleCIBuildDirectory, required = False ) or baseDir
		subfolder = make_foldername_from_string( rev )
		directory = os.path.normpath( os.path.join( buildRoot, name, buildType, subfolder ) )
		# prepare build directory:
		if os.path.isdir( directory ):
			mApp().debug( self, 'found remainders of a previous build, nuking it...' )
			try:
				rmtree( directory )
				mApp().debug( self, '...that was good!' )
			except ( OSError, IOError ) as e:
				raise ConfigurationError( 'Remnants of a previous build exist at "{0}" and cannot be deleted, bad. Reason: {1}.'
					.format( directory, e ) )
		try:
			os.makedirs( directory )
		except ( OSError, IOError )as e:
			raise ConfigurationError( 'Cannot create required build directory "{0}"!'.format( directory ) )
		mApp().message( self, 'starting build job for project "{0}" at revision {1}.'
					.format( buildInfo.getProjectName(), rev ) )
		with EnvironmentSaver():
			os.chdir( directory )
			extend_debug_prefix( buildInfo.getProjectName() )
			iface = BuildScriptInterface( os.path.abspath( buildInfo.getBuildScript() ) )
			runner = iface.executeBuildInfo( buildInfo )
			try:
				with open( 'buildscript.log', 'w' ) as f:
					text = runner.getStdOutAsString()
					f.write( text.decode() )
			except Exception as e:
				mApp().message( self, 'Problem! saving the build script output failed during handling an exception! {0}'
					.format( e ) )
			if runner.getReturnCode() != 0:
				mApp().message( self, 'build failed for project "{0}" at revision {1}'.format( buildInfo.getProjectName(), rev ) )
				# FIXME send out email reports on configuration or MOM errors
				mApp().message( self, 'exit code {0}'.format( runner.getReturnCode() ) )
				print( """\
-->   ____        _ _     _   _____     _ _          _ 
-->  | __ ) _   _(_) | __| | |  ___|_ _(_) | ___  __| |
-->  |  _ \| | | | | |/ _` | | |_ / _` | | |/ _ \/ _` |
-->  | |_) | |_| | | | (_| | |  _| (_| | | |  __/ (_| |
-->  |____/ \__,_|_|_|\__,_| |_|  \__,_|_|_|\___|\__,_|
--> 
""" )
				return False
			else:
				mApp().message( self, 'build succeeded for project "{0}" at revision {1}'.format( buildInfo.getProjectName(), rev ) )
				print( """\
-->   _         _ _    _      _
-->  | |__ _  _(_) |__| |  __| |___ _ _  ___
-->  | '_ \ || | | / _` | / _` / _ \ ' \/ -_)
-->  |_.__/\_,_|_|_\__,_| \__,_\___/_||_\___|
--> 
""" )
				return True