@@ -102,5 +102,147 @@ podTemplate(
102102 )
103103 }
104104 }
105+
106+ stage(' Setup Post-Creation Scripts' ) {
107+ // Load post-creation scripts configuration
108+ def postCreationEnabled = getConfigValue(' POST_CREATION_SCRIPTS_ENABLED' , ' ods-configuration/ods-core.env' , ' false' )
109+
110+ if (! postCreationEnabled || postCreationEnabled != ' true' ) {
111+ echo(" Post-creation scripts are disabled or not configured. Skipping setup." )
112+ env. POST_SCRIPTS_ENABLED = ' false'
113+ return
114+ }
115+
116+ def scriptsOrder = getConfigValue(' POST_CREATION_SCRIPTS_ORDER' , ' ods-configuration/ods-core.env' ). trim()
117+ if (! scriptsOrder || scriptsOrder. trim(). isEmpty()) {
118+ echo(" No scripts specified in POST_CREATION_SCRIPTS_ORDER. Skipping setup." )
119+ env. POST_SCRIPTS_ENABLED = ' false'
120+ return
121+ }
122+
123+ echo(" Post-creation scripts are enabled. Retrieving configuration..." )
124+
125+ // Get scripts repository configuration
126+ def scriptsRepoUrl = getConfigValue(' POST_CREATION_SCRIPTS_REPO_URL' , ' ods-configuration/ods-core.env' )
127+ def scriptsBranch = getConfigValue(' POST_CREATION_SCRIPTS_BRANCH' , ' ods-configuration/ods-core.env' , ' master' )
128+ def scriptsConfigFile = getConfigValue(' POST_CREATION_SCRIPTS_CONFIG_FILE' , ' ods-configuration/ods-core.env' )
129+
130+ def configRepoUrl = getConfigValue(' POST_CREATION_SCRIPTS_CONFIG_REPO_URL' , ' ods-configuration/ods-core.env' )
131+ def configRepoBranch = getConfigValue(' POST_CREATION_SCRIPTS_CONFIG_REPO_BRANCH' , ' ods-configuration/ods-core.env' , ' master' )
132+
133+ // Check if required configuration is missing
134+ if (! scriptsRepoUrl || scriptsRepoUrl. trim(). isEmpty()) {
135+ echo(" POST_CREATION_SCRIPTS_REPO_URL is not configured. Skipping setup." )
136+ env. POST_SCRIPTS_ENABLED = ' false'
137+ return
138+ }
139+
140+ if (! scriptsConfigFile || scriptsConfigFile. trim(). isEmpty()) {
141+ echo(" POST_CREATION_SCRIPTS_CONFIG_FILE is not configured. Skipping setup." )
142+ env. POST_SCRIPTS_ENABLED = ' false'
143+ return
144+ }
145+
146+ echo(" Scripts repository: ${ scriptsRepoUrl} " )
147+ echo(" Scripts branch: ${ scriptsBranch} " )
148+ echo(" Scripts order: ${ scriptsOrder} " )
149+ echo(" Scripts config file: ${ scriptsConfigFile} " )
150+ echo(" Config repo URL: ${ configRepoUrl} " )
151+ echo(" Config repo branch: ${ configRepoBranch} " )
152+
153+ def credentialsId = " ${ pipelineOpenShiftProject} -cd-user-with-password"
154+
155+ // Clone the scripts repository
156+ checkout([
157+ $class : ' GitSCM' ,
158+ branches : [[name : " */${ scriptsBranch} " ]],
159+ doGenerateSubmoduleConfigurations : false ,
160+ extensions : [[
161+ $class : ' RelativeTargetDirectory' ,
162+ relativeTargetDir : ' post-creation-scripts'
163+ ]],
164+ submoduleCfg : [],
165+ userRemoteConfigs : [[
166+ credentialsId : " ${ credentialsId} " ,
167+ url : " ${ scriptsRepoUrl} "
168+ ]]
169+ ])
170+
171+ checkout([
172+ $class : ' GitSCM' ,
173+ branches : [[name : " */${ configRepoBranch} " ]],
174+ doGenerateSubmoduleConfigurations : false ,
175+ extensions : [[
176+ $class : ' RelativeTargetDirectory' ,
177+ relativeTargetDir : ' post-creation-config'
178+ ]],
179+ submoduleCfg : [],
180+ userRemoteConfigs : [[
181+ credentialsId : " ${ credentialsId} " ,
182+ url : " ${ configRepoUrl} "
183+ ]]
184+ ])
185+
186+ // Store configuration for next stage
187+ env. POST_SCRIPTS_ENABLED = ' true'
188+ env. POST_SCRIPTS_ORDER = scriptsOrder
189+ env. POST_SCRIPTS_CONFIG_FILE = scriptsConfigFile
190+ }
191+
192+ stage(' Execute Post-Creation Scripts' ) {
193+ dir(' post-creation-scripts' ) {
194+
195+ if (env. POST_SCRIPTS_ENABLED != ' true' ) {
196+ echo(" Post-creation scripts execution is disabled. Skipping." )
197+ return
198+ }
199+
200+ def credentialsId = " ${ odsNamespace} -cd-user-with-password"
201+
202+ def scripts = env. POST_SCRIPTS_ORDER . split(' ,' )
203+ def odsConfigPath = " ${ env.WORKSPACE} /ods-configuration/ods-core.env"
204+ def scriptsConfigPath = " ${ env.WORKSPACE} /post-creation-config/${ env.POST_SCRIPTS_CONFIG_FILE} "
205+
206+ withCredentials([usernamePassword(credentialsId : " ${ credentialsId} " , passwordVariable : ' password' , usernameVariable : ' username' )]) {
207+ withEnv([
208+ " PROJECT_ID=${ projectId} " ,
209+ " PROJECT_GROUPS=${ projectGroups} " ,
210+ " PROJECT_ADMIN=${ projectAdmins} " ,
211+ " ODS_NAMESPACE=${ odsNamespace} " ,
212+ " ODS_IMAGE_TAG=${ odsImageTag} " ,
213+ " ODS_GIT_REF=${ odsGitRef} " ,
214+ " ODS_BITBUCKET_PROJECT=${ odsBitbucketProject} " ,
215+ " BITBUCKET_URL=${ bitbucketUrl} " ,
216+ " DOCKER_REGISTRY=${ dockerRegistry} " ,
217+ " CD_USERNAME=${ username} " ,
218+ " CD_PASSWORD=${ password} " ,
219+ " CD_USER_CREDENTIALS_ID=${ credentialsId} "
220+ ]) {
221+ echo(" Environment variables for scripts:" )
222+
223+ for (script in scripts) {
224+ def scriptName = script. trim()
225+ def scriptPath = " post-project-creation/${ scriptName} "
226+
227+ echo(" Executing script: ${ scriptName} " )
228+
229+ sh(
230+ script : """
231+ "${ scriptPath} " "${ odsConfigPath} " "${ scriptsConfigPath} "
232+ """ ,
233+ label : " Execute script: ${ scriptName} "
234+ )
235+ }
236+ }
237+ }
238+ }
239+ }
105240 }
106241}
242+
243+ def getConfigValue (field , file , defaultValue = ' ' ) {
244+ return sh(
245+ script : " grep '^${ field} =' ${ file} | cut -d'=' -f2 | tr -d '\" ' || echo '${ defaultValue} '" ,
246+ returnStdout : true
247+ ). trim()
248+ }
0 commit comments