@@ -8,8 +8,12 @@ import groovy.json.JsonSlurperClassic
8899emailSecList
= ' [email protected] ' 1010gitCredID = ' marklogic-builder-github'
11+ operatorRegistry = ' ml-marklogic-operator-dev.bed-artifactory.bedford.progress.com'
1112JIRA_ID = ' '
1213JIRA_ID_PATTERN = / (?i)(MLE)-\d {3,6}/
14+ operatorRepo = ' marklogic-kubernetes-operator'
15+ timeStamp = new Date (). format(' yyyyMMdd' )
16+ branchNameTag = env. BRANCH_NAME . replaceAll(' /' , ' -' )
1317
1418// Define local funtions
1519void preBuildCheck () {
@@ -126,15 +130,15 @@ void runTests() {
126130}
127131
128132void runMinikubeSetup () {
129- sh '''
130- make e2e-setup-minikube
131- '''
133+ sh """
134+ make e2e-setup-minikube IMG= ${ operatorRepo } : ${ VERSION }
135+ """
132136}
133137
134138void runE2eTests () {
135- sh '''
136- make e2e-test
137- '''
139+ sh """
140+ make e2e-test IMG= ${ operatorRepo } : ${ VERSION }
141+ """
138142}
139143
140144void runMinikubeCleanup () {
@@ -143,9 +147,43 @@ void runMinikubeCleanup() {
143147 '''
144148}
145149
146- void runSecurityScan () {
147- build job : ' securityscans/Blackduck/KubeNinjas/kubernetes-operator' , wait : false , parameters : [ string(name : ' branch' , value : " ${ env.BRANCH_NAME} " ) ]
150+ void runBlackDuckScan () {
151+ // Trigger BlackDuck scan job with CONTAINER_IMAGES parameter when params.PUBLISH_IMAGE is true
152+ if (params. PUBLISH_IMAGE ) {
153+ build job : ' securityscans/Blackduck/KubeNinjas/kubernetes-operator' , wait : false , parameters : [ string(name : ' branch' , value : " ${ env.BRANCH_NAME} " ), string(name : ' CONTAINER_IMAGES' , value : " ${ operatorRepo} :${ VERSION} -${ branchNameTag} " ) ]
154+ } else {
155+ build job : ' securityscans/Blackduck/KubeNinjas/kubernetes-operator' , wait : false , parameters : [ string(name : ' branch' , value : " ${ env.BRANCH_NAME} " ) ]
156+ }
157+ }
158+
159+ /**
160+ * Publishes the built Docker image to the internal Artifactory registry.
161+ * Tags the image with multiple tags (version-specific, branch-specific, latest).
162+ * Requires Artifactory credentials.
163+ */
164+ void publishToInternalRegistry () {
165+ withCredentials([usernamePassword(credentialsId : ' builder-credentials-artifactory' , passwordVariable : ' docker_password' , usernameVariable : ' docker_user' )]) {
166+
167+ sh """
168+ # make sure to logout first to avoid issues with cached credentials
169+ docker logout ${ operatorRegistry}
170+ echo "${ docker_password} " | docker login --username ${ docker_user} --password-stdin ${ operatorRegistry}
171+
172+ # Create tags
173+ docker tag ${ operatorRepo} :${ VERSION} ${ operatorRegistry} /${ operatorRepo} :${ VERSION}
174+ docker tag ${ operatorRepo} :${ VERSION} ${ operatorRegistry} /${ operatorRepo} :${ VERSION} -${ branchNameTag}
175+ docker tag ${ operatorRepo} :${ VERSION} ${ operatorRegistry} /${ operatorRepo} :${ VERSION} -${ branchNameTag} -${ timeStamp}
176+ docker tag ${ operatorRepo} :${ VERSION} ${ operatorRegistry} /${ operatorRepo} :latest
177+
178+ # Push images to internal registry
179+ docker push ${ operatorRegistry} /${ operatorRepo} :${ VERSION}
180+ docker push ${ operatorRegistry} /${ operatorRepo} :${ VERSION} -${ branchNameTag}
181+ docker push ${ operatorRegistry} /${ operatorRepo} :${ VERSION} -${ branchNameTag} -${ timeStamp}
182+ docker push ${ operatorRegistry} /${ operatorRepo} :latest
183+ """
184+ }
148185}
186+
149187pipeline {
150188 agent {
151189 label {
@@ -157,16 +195,17 @@ pipeline {
157195 buildDiscarder logRotator(artifactDaysToKeepStr : ' 20' , artifactNumToKeepStr : ' ' , daysToKeepStr : ' 30' , numToKeepStr : ' ' )
158196 skipStagesAfterUnstable()
159197 }
160- // triggers {
161- // //TODO: add scheduled runs
162- // }
163- // environment {
164- // //TODO
165- // }
198+
199+ triggers {
200+ // Trigger nightly builds on the develop branch
201+ parameterizedCron( env . BRANCH_NAME == ' develop ' ? ''' 00 05 * * * % E2E_MARKLOGIC_IMAGE_VERSION=ml-docker-db-dev-tierpoint.bed-artifactory.bedford.progress.com/marklogic/marklogic-server-ubi-rootless:latest-12
202+ 00 05 * * * % E2E_MARKLOGIC_IMAGE_VERSION=ml-docker-db-dev-tierpoint.bed-artifactory.bedford.progress.com/marklogic/marklogic-server-ubi-rootless:latest-11; PUBLISH_IMAGE=false ''' : ' ' )
203+ }
166204
167205 parameters {
168206 string(name : ' E2E_MARKLOGIC_IMAGE_VERSION' , defaultValue : ' ml-docker-db-dev-tierpoint.bed-artifactory.bedford.progress.com/marklogic/marklogic-server-ubi-rootless:latest-12' , description : ' Docker image to use for tests.' , trim : true )
169- string(name : ' IMG' , defaultValue : ' testrepo/marklogic-operator-image-dev:internal' , description : ' Docker image for Running Operator Container' , trim : true )
207+ string(name : ' VERSION' , defaultValue : ' 1.1.0' , description : ' Version to tag the image with.' , trim : true )
208+ booleanParam(name : ' PUBLISH_IMAGE' , defaultValue : false , description : ' Publish image to internal registry' )
170209 string(name : ' emailList' , defaultValue : emailList, description : ' List of email for build notification' , trim : true )
171210 }
172211
@@ -177,12 +216,6 @@ pipeline {
177216 }
178217 }
179218
180- stage(' Run-Security-Scan' ) {
181- steps {
182- runSecurityScan()
183- }
184- }
185-
186219 stage(' Run-tests' ) {
187220 steps {
188221 runTests()
@@ -206,6 +239,26 @@ pipeline {
206239 runMinikubeCleanup()
207240 }
208241 }
242+
243+ // Publish image to internal registries (conditional)
244+ stage(' Publish Image' ) {
245+ when {
246+ anyOf {
247+ branch ' develop'
248+ expression { return params. PUBLISH_IMAGE }
249+ }
250+ }
251+ steps {
252+ publishToInternalRegistry()
253+ }
254+ }
255+
256+ stage(' Run-BlackDuck-Scan' ) {
257+
258+ steps {
259+ runBlackDuckScan()
260+ }
261+ }
209262
210263 }
211264
0 commit comments