allow to set a tag for building in ci
This commit is contained in:
		
							parent
							
								
									707c00b850
								
							
						
					
					
						commit
						9ddcbdc34a
					
				|  | @ -1,6 +1,10 @@ | ||||||
| # Use the latest 2.1 version of CircleCI pipeline process engine. | # Use the latest 2.1 version of CircleCI pipeline process engine. | ||||||
| # See: https://circleci.com/docs/configuration-reference | # See: https://circleci.com/docs/configuration-reference | ||||||
| version: 2.1 | version: 2.1 | ||||||
|  | # set the filter to allow a build for any sha tag | ||||||
|  | filters: | ||||||
|  |   tags: | ||||||
|  |     only: /.*/ | ||||||
| parameters: | parameters: | ||||||
|   run_build: |   run_build: | ||||||
|     type: boolean |     type: boolean | ||||||
|  |  | ||||||
|  | @ -12,6 +12,7 @@ const defaultBranch='master'; | ||||||
| const defaultUser='wellenvogel'; | const defaultUser='wellenvogel'; | ||||||
| const defaultRepo='esp32-nmea2000'; | const defaultRepo='esp32-nmea2000'; | ||||||
| const TABLENAME="CIBUILDS"; | const TABLENAME="CIBUILDS"; | ||||||
|  | const KEEPINTERVAL="30"; //days
 | ||||||
| 
 | 
 | ||||||
| function getTokenHeaders(){ | function getTokenHeaders(){ | ||||||
|     global $CI_TOKEN; |     global $CI_TOKEN; | ||||||
|  | @ -92,20 +93,25 @@ function getArtifacts($job,$slug){ | ||||||
|     return getJson($url,getTokenHeaders(),true); |     return getJson($url,getTokenHeaders(),true); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function insertPipeline($id,$param){ | function insertPipeline($id,$requestParam){ | ||||||
|     $database=openDb(); |     $database=openDb(); | ||||||
|     if (! isset($database)) return false; |     if (! isset($database)) return false; | ||||||
|  |     $param=$requestParam['parameters']; | ||||||
|     try { |     try { | ||||||
|         $status='created'; |         $status='created'; | ||||||
|  |         $tag=null; | ||||||
|  |         if (isset($requestParam['tag'])) $tag=$requestParam['tag']; | ||||||
|         $stmt = $database->prepare("INSERT into " . TABLENAME . |         $stmt = $database->prepare("INSERT into " . TABLENAME . | ||||||
|             "(id,status,config,environment,buildflags) VALUES (?,?,?,?,?)"); |             "(id,status,config,environment,buildflags,tag) VALUES (?,?,?,?,?,?)"); | ||||||
|         $stmt->bind_param("sssss", |         $stmt->bind_param("ssssss", | ||||||
|         $id, |         $id, | ||||||
|         $status, |         $status, | ||||||
|         $param['config'], |         $param['config'], | ||||||
|         $param['environment'], |         $param['environment'], | ||||||
|         $param['build_flags']); |         $param['build_flags'], | ||||||
|  |         $tag); | ||||||
|         $stmt->execute(); |         $stmt->execute(); | ||||||
|  |         $database->query("DELETE from ". TABLENAME. " where timestamp < NOW() - interval ". KEEPINTERVAL. " DAY"); | ||||||
|         return true; |         return true; | ||||||
|     } catch (Exception $e) { |     } catch (Exception $e) { | ||||||
|         error_log("insert pipeline $id failed: $e"); |         error_log("insert pipeline $id failed: $e"); | ||||||
|  | @ -142,13 +148,14 @@ function findPipeline($param) | ||||||
|         return false; |         return false; | ||||||
|     try { |     try { | ||||||
|         $stmt = null; |         $stmt = null; | ||||||
|  |         $database->query("DELETE from ". TABLENAME. " where timestamp < NOW() - interval ". KEEPINTERVAL. " DAY"); | ||||||
|         if (isset($param['tag'])) { |         if (isset($param['tag'])) { | ||||||
|             $stmt = $database->prepare("SELECT id,UNIX_TIMESTAMP(timestamp) from " . TABLENAME . |             $stmt = $database->prepare("SELECT id,UNIX_TIMESTAMP(timestamp) from " . TABLENAME . | ||||||
|                 " where status='success' and environment=? and buildflags=? and tag=? order by timestamp desc"); |                 " where status IN('success','running','created') and environment=? and buildflags=? and tag=? order by timestamp desc"); | ||||||
|             $stmt->bind_param("sss", $param['environment'], $param['buildflags'], $param['tag']); |             $stmt->bind_param("sss", $param['environment'], $param['buildflags'], $param['tag']); | ||||||
|         } else { |         } else { | ||||||
|             $stmt = $database->prepare("SELECT id,UNIX_TIMESTAMP(timestamp) from " . TABLENAME . |             $stmt = $database->prepare("SELECT id,UNIX_TIMESTAMP(timestamp) from " . TABLENAME . | ||||||
|                 " where status='success' and environment=? and buildflags=? order by timestamp desc"); |                 " where status IN('success','running','created') and environment=? and buildflags=? order by timestamp desc"); | ||||||
|             $stmt->bind_param("ss", $param['environment'], $param['buildflags']); |             $stmt->bind_param("ss", $param['environment'], $param['buildflags']); | ||||||
|         } |         } | ||||||
|         $stmt->execute(); |         $stmt->execute(); | ||||||
|  | @ -244,9 +251,8 @@ try { | ||||||
|         if ($action == 'start'){ |         if ($action == 'start'){ | ||||||
|             addVars( |             addVars( | ||||||
|                 $par, |                 $par, | ||||||
|                 ['environment','buildflags','config','suffix','branch','user','repo'], |                 ['environment','buildflags','config','suffix','user','repo'], | ||||||
|                 array('suffix'=>'', |                 array('suffix'=>'', | ||||||
|                     'branch'=>defaultBranch, |  | ||||||
|                     'config'=>'{}', |                     'config'=>'{}', | ||||||
|                     'user'=>defaultUser, |                     'user'=>defaultUser, | ||||||
|                     'repo'=>defaultRepo, |                     'repo'=>defaultRepo, | ||||||
|  | @ -254,7 +260,6 @@ try { | ||||||
|                     ) |                     ) | ||||||
|             ); |             ); | ||||||
|             $requestParam=array( |             $requestParam=array( | ||||||
|                 'branch'=>$par['branch'], |  | ||||||
|                 'parameters'=> array( |                 'parameters'=> array( | ||||||
|                     'run_build'=>true, |                     'run_build'=>true, | ||||||
|                     'environment'=>$par['environment'], |                     'environment'=>$par['environment'], | ||||||
|  | @ -263,10 +268,16 @@ try { | ||||||
|                     'build_flags'=>$par['buildflags'] |                     'build_flags'=>$par['buildflags'] | ||||||
|                 ) |                 ) | ||||||
|             ); |             ); | ||||||
|  |             if (isset($_REQUEST['tag'])){ | ||||||
|  |                 $requestParam['tag']=safeName($_REQUEST['tag']); | ||||||
|  |             } | ||||||
|  |             else{ | ||||||
|  |                 $requestParam['branch']=defaultBranch; | ||||||
|  |             } | ||||||
|             $userRepo=fillUserAndRepo(null,$par); |             $userRepo=fillUserAndRepo(null,$par); | ||||||
|             $url=apiBase."/".replaceVars(apiRepo,$userRepo)."/pipeline"; |             $url=apiBase."/".replaceVars(apiRepo,$userRepo)."/pipeline"; | ||||||
|             $rt=getJson($url,getTokenHeaders(),true,$requestParam); |             $rt=getJson($url,getTokenHeaders(),true,$requestParam); | ||||||
|             insertPipeline($rt['id'],$requestParam['parameters']); |             insertPipeline($rt['id'],$requestParam); | ||||||
|             echo (json_encode($rt)); |             echo (json_encode($rt)); | ||||||
|             exit(0); |             exit(0); | ||||||
|         } |         } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 andreas
						andreas