| 
									
										
										
										
											2019-02-05 15:37:59 +01:00
										 |  |  | import com.sap.piper.ConfigurationLoader | 
					
						
							|  |  |  | import com.sap.piper.ConfigurationMerger | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-11 15:12:03 +02:00
										 |  |  | class commonPipelineEnvironment implements Serializable { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 09:55:38 +01:00
										 |  |  |     //stores version of the artifact which is build during pipeline run
 | 
					
						
							|  |  |  |     def artifactVersion | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-17 12:05:11 +02:00
										 |  |  |     //Stores the current buildResult
 | 
					
						
							|  |  |  |     String buildResult = 'SUCCESS' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 13:17:33 +01:00
										 |  |  |     //stores the gitCommitId as well as additional git information for the build during pipeline run
 | 
					
						
							| 
									
										
										
										
											2018-09-17 16:51:13 +02:00
										 |  |  |     String gitCommitId | 
					
						
							|  |  |  |     String gitSshUrl | 
					
						
							| 
									
										
										
										
											2018-10-17 09:54:04 +02:00
										 |  |  |     String gitHttpsUrl | 
					
						
							|  |  |  |     String gitBranch | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //GiutHub specific information
 | 
					
						
							|  |  |  |     String githubOrg | 
					
						
							|  |  |  |     String githubRepo | 
					
						
							| 
									
										
										
										
											2018-02-07 13:17:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     //stores properties for a pipeline which build an artifact and then bundles it into a container
 | 
					
						
							|  |  |  |     private Map appContainerProperties = [:] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 12:03:06 +01:00
										 |  |  |     Map configuration = [:] | 
					
						
							| 
									
										
										
										
											2018-01-24 09:55:38 +01:00
										 |  |  |     Map defaultConfiguration = [:] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //each Map in influxCustomDataMap represents a measurement in Influx. Additional measurements can be added as a new Map entry of influxCustomDataMap
 | 
					
						
							| 
									
										
										
										
											2018-05-30 12:00:13 +02:00
										 |  |  |     private Map influxCustomDataMap = [pipeline_data: [:], step_data: [:]] | 
					
						
							| 
									
										
										
										
											2019-01-17 15:42:03 +01:00
										 |  |  |     //each Map in influxCustomDataMapTags represents tags for certain measurement in Influx. Tags are required in Influx for easier querying data
 | 
					
						
							|  |  |  |     private Map influxCustomDataMapTags = [pipeline_data: [:]] | 
					
						
							| 
									
										
										
										
											2018-01-24 09:55:38 +01:00
										 |  |  |     //influxCustomData represents measurement jenkins_custom_data in Influx. Metrics can be written into this map
 | 
					
						
							|  |  |  |     private Map influxCustomData = [:] | 
					
						
							| 
									
										
										
										
											2019-01-17 15:42:03 +01:00
										 |  |  |     //influxCustomDataTags represents tags in Influx. Tags are required in Influx for easier querying data
 | 
					
						
							|  |  |  |     private Map influxCustomDataTags = [:] | 
					
						
							| 
									
										
										
										
											2017-12-06 12:03:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 16:51:13 +02:00
										 |  |  |     String mtarFilePath | 
					
						
							| 
									
										
										
										
											2017-07-11 15:12:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 13:47:32 +01:00
										 |  |  |     String transportRequestId | 
					
						
							| 
									
										
										
										
											2018-11-06 14:36:40 +01:00
										 |  |  |     String changeDocumentId | 
					
						
							| 
									
										
										
										
											2018-11-06 13:47:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-30 12:00:13 +02:00
										 |  |  |     def reset() { | 
					
						
							|  |  |  |         appContainerProperties = [:] | 
					
						
							|  |  |  |         artifactVersion = null | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         configuration = [:] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         gitCommitId = null | 
					
						
							|  |  |  |         gitSshUrl = null | 
					
						
							| 
									
										
										
										
											2018-10-17 09:54:04 +02:00
										 |  |  |         gitHttpsUrl = null | 
					
						
							|  |  |  |         gitBranch = null | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         githubOrg = null | 
					
						
							|  |  |  |         githubRepo = null | 
					
						
							| 
									
										
										
										
											2018-05-30 12:00:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         influxCustomData = [:] | 
					
						
							| 
									
										
										
										
											2019-01-17 15:42:03 +01:00
										 |  |  |         influxCustomDataTags = [:] | 
					
						
							| 
									
										
										
										
											2018-05-30 12:00:13 +02:00
										 |  |  |         influxCustomDataMap = [pipeline_data: [:], step_data: [:]] | 
					
						
							| 
									
										
										
										
											2019-01-17 15:42:03 +01:00
										 |  |  |         influxCustomDataMapTags = [pipeline_data: [:]] | 
					
						
							| 
									
										
										
										
											2018-05-30 12:00:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         mtarFilePath = null | 
					
						
							| 
									
										
										
										
											2018-11-06 13:47:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         transportRequestId = null | 
					
						
							| 
									
										
										
										
											2018-11-06 14:36:40 +01:00
										 |  |  |         changeDocumentId = null | 
					
						
							| 
									
										
										
										
											2018-05-30 12:00:13 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 13:17:33 +01:00
										 |  |  |     def setAppContainerProperty(property, value) { | 
					
						
							|  |  |  |         appContainerProperties[property] = value | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def getAppContainerProperty(property) { | 
					
						
							|  |  |  |         return appContainerProperties[property] | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-17 15:42:03 +01:00
										 |  |  |     // goes into measurement jenkins_data
 | 
					
						
							|  |  |  |     def setInfluxCustomDataEntry(field, value) { | 
					
						
							|  |  |  |         influxCustomData[field] = value | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     // goes into measurement jenkins_data
 | 
					
						
							| 
									
										
										
										
											2018-01-24 09:55:38 +01:00
										 |  |  |     def getInfluxCustomData() { | 
					
						
							|  |  |  |         return influxCustomData | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-17 15:42:03 +01:00
										 |  |  |     // goes into measurement jenkins_data
 | 
					
						
							|  |  |  |     def setInfluxCustomDataTagsEntry(tag, value) { | 
					
						
							|  |  |  |         influxCustomDataTags[tag] = value | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // goes into measurement jenkins_data
 | 
					
						
							|  |  |  |     def getInfluxCustomDataTags() { | 
					
						
							|  |  |  |         return influxCustomDataTags | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void setInfluxCustomDataMapEntry(measurement, field, value) { | 
					
						
							|  |  |  |         if (!influxCustomDataMap[measurement]) { | 
					
						
							|  |  |  |             influxCustomDataMap[measurement] = [:] | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         influxCustomDataMap[measurement][field] = value | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-24 09:55:38 +01:00
										 |  |  |     def getInfluxCustomDataMap() { | 
					
						
							|  |  |  |         return influxCustomDataMap | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-17 15:42:03 +01:00
										 |  |  |     def setInfluxCustomDataMapTagsEntry(measurement, tag, value) { | 
					
						
							|  |  |  |         if (!influxCustomDataMapTags[measurement]) { | 
					
						
							|  |  |  |             influxCustomDataMapTags[measurement] = [:] | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         influxCustomDataMapTags[measurement][tag] = value | 
					
						
							| 
									
										
										
										
											2018-08-15 11:41:01 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-01-17 15:42:03 +01:00
										 |  |  |     def getInfluxCustomDataMapTags() { | 
					
						
							|  |  |  |         return influxCustomDataMapTags | 
					
						
							| 
									
										
										
										
											2018-08-15 11:41:01 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-17 15:42:03 +01:00
										 |  |  |     def setInfluxStepData(key, value) { | 
					
						
							|  |  |  |         setInfluxCustomDataMapEntry('step_data', key, value) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     def getInfluxStepData(key) { | 
					
						
							|  |  |  |         return influxCustomDataMap.step_data[key] | 
					
						
							| 
									
										
										
										
											2018-01-24 09:55:38 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-21 20:23:23 +01:00
										 |  |  |     def setInfluxPipelineData(key, value) { | 
					
						
							| 
									
										
										
										
											2019-01-17 15:42:03 +01:00
										 |  |  |         setInfluxCustomDataMapEntry('pipeline_data', key, value) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-03-21 20:23:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def setPipelineMeasurement(key, value){ | 
					
						
							|  |  |  |         setInfluxPipelineData(key, value) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-01-17 15:42:03 +01:00
										 |  |  |     def getPipelineMeasurement(key) { | 
					
						
							|  |  |  |         return influxCustomDataMap.pipeline_data[key] | 
					
						
							| 
									
										
										
										
											2018-01-24 09:55:38 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-02-05 15:37:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Map getStepConfiguration(stepName, stageName = env.STAGE_NAME, includeDefaults = true) { | 
					
						
							|  |  |  |         Map defaults = [:] | 
					
						
							|  |  |  |         if (includeDefaults) { | 
					
						
							|  |  |  |             defaults = ConfigurationLoader.defaultGeneralConfiguration() | 
					
						
							|  |  |  |             defaults = ConfigurationMerger.merge(ConfigurationLoader.defaultStepConfiguration(null, stepName), null, defaults) | 
					
						
							|  |  |  |             defaults = ConfigurationMerger.merge(ConfigurationLoader.defaultStageConfiguration(null, stageName), null, defaults) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         Map config = ConfigurationMerger.merge(configuration.get('general') ?: [:], null, defaults) | 
					
						
							|  |  |  |         config = ConfigurationMerger.merge(configuration.get('steps')?.get(stepName) ?: [:], null, config) | 
					
						
							|  |  |  |         config = ConfigurationMerger.merge(configuration.get('stages')?.get(stageName) ?: [:], null, config) | 
					
						
							|  |  |  |         return config | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-11 15:12:03 +02:00
										 |  |  | } |