Skip to content

Commit 1c8cf66

Browse files
author
Vitaly Korolev
committed
Add publishing step and enable scheduled builds
1 parent 26295cc commit 1c8cf66

File tree

1 file changed

+52
-8
lines changed

1 file changed

+52
-8
lines changed

Jenkinsfile

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import groovy.json.JsonSlurperClassic
88
99
emailSecList = '[email protected]'
1010
gitCredID = 'marklogic-builder-github'
11+
operatorRegistry = 'ml-docker-db-dev-tierpoint.bed-artifactory.bedford.progress.com'
1112
JIRA_ID = ''
1213
JIRA_ID_PATTERN = /(?i)(MLE)-\d{3,6}/
14+
operatorRepo = 'ml-marklogic-operator-dev/marklogic-operator-kubernetes'
1315

1416
// Define local funtions
1517
void preBuildCheck() {
@@ -127,7 +129,7 @@ void runTests() {
127129

128130
void runMinikubeSetup() {
129131
sh '''
130-
make e2e-setup-minikube
132+
make e2e-setup-minikube IMG=${operatorRepo}:${VERSION}
131133
'''
132134
}
133135

@@ -146,6 +148,34 @@ void runMinikubeCleanup() {
146148
void runSecurityScan() {
147149
build job: 'securityscans/Blackduck/KubeNinjas/kubernetes-operator', wait: false, parameters: [ string(name: 'branch', value: "${env.BRANCH_NAME}") ]
148150
}
151+
152+
/**
153+
* Publishes the built Docker image to the internal Artifactory registry.
154+
* Tags the image with multiple tags (version-specific, branch-specific, latest).
155+
* Requires Artifactory credentials.
156+
*/
157+
void publishToInternalRegistry() {
158+
withCredentials([usernamePassword(credentialsId: 'builder-credentials-artifactory', passwordVariable: 'docker_password', usernameVariable: 'docker_user')]) {
159+
timeStamp = new Date().format('yyyyMMdd')
160+
sh """
161+
# make sure to logout first to avoid issues with cached credentials
162+
docker logout ${operatorRegistry}
163+
echo "${docker_password}" | docker login --username ${docker_user} --password-stdin ${operatorRegistry}
164+
165+
# Create tags
166+
docker tag ${operatorRepo}:${VERSION} ${operatorRegistry}/${operatorRepo}:${VERSION}
167+
docker tag ${operatorRepo}:${VERSION} ${operatorRegistry}/${operatorRepo}:${VERSION}-${env.BRANCH_NAME//\//-}
168+
docker tag ${operatorRepo}:${VERSION} ${operatorRegistry}/${operatorRepo}:${VERSION}-${env.BRANCH_NAME//\//-}-${timeStamp}
169+
docker tag ${operatorRepo}:${VERSION} ${operatorRegistry}/latest
170+
171+
# Push images to internal registry
172+
docker push ${operatorRegistry}/${operatorRepo}:${VERSION}
173+
docker push ${operatorRegistry}/${operatorRepo}:${VERSION}-${env.BRANCH_NAME//\//-}
174+
docker push ${operatorRegistry}/${operatorRepo}:${VERSION}-${env.BRANCH_NAME//\//-}-${timeStamp}
175+
docker push ${operatorRegistry}/latest
176+
"""
177+
}
178+
149179
pipeline {
150180
agent {
151181
label {
@@ -157,16 +187,17 @@ pipeline {
157187
buildDiscarder logRotator(artifactDaysToKeepStr: '20', artifactNumToKeepStr: '', daysToKeepStr: '30', numToKeepStr: '')
158188
skipStagesAfterUnstable()
159189
}
160-
// triggers {
161-
// //TODO: add scheduled runs
162-
// }
163-
// environment {
164-
// //TODO
165-
// }
190+
191+
triggers {
192+
// Trigger nightly builds on the develop branch
193+
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
194+
00 05 * * * % E2E_MARKLOGIC_IMAGE_VERSION=ml-docker-db-dev-tierpoint.bed-artifactory.bedford.progress.com/marklogic/marklogic-server-ubi-rootless:latest-11''' : '')
195+
}
166196

167197
parameters {
168198
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)
199+
string(name: 'VERSION', defaultValue: '1.1.0', description: 'Version to tag the image with.', trim: true)
200+
booleanParam(name: 'PUBLISH_IMAGE', defaultValue: false, description: 'Publish image to internal registry')
170201
string(name: 'emailList', defaultValue: emailList, description: 'List of email for build notification', trim: true)
171202
}
172203

@@ -206,6 +237,19 @@ pipeline {
206237
runMinikubeCleanup()
207238
}
208239
}
240+
241+
// Publish image to internal registries (conditional)
242+
stage('Publish Image') {
243+
when {
244+
anyOf {
245+
branch 'develop'
246+
expression { return params.PUBLISH_IMAGE }
247+
}
248+
}
249+
steps {
250+
publishToInternalRegistry()
251+
}
252+
}
209253

210254
}
211255

0 commit comments

Comments
 (0)