Skip to content

Commit 667c031

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

File tree

2 files changed

+60
-14
lines changed

2 files changed

+60
-14
lines changed

Jenkinsfile

Lines changed: 59 additions & 13 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-marklogic-operator-dev.bed-artifactory.bedford.progress.com'
1112
JIRA_ID = ''
1213
JIRA_ID_PATTERN = /(?i)(MLE)-\d{3,6}/
14+
operatorRepo = 'marklogic-kubernetes-operator'
1315

1416
// Define local funtions
1517
void preBuildCheck() {
@@ -126,15 +128,15 @@ void runTests() {
126128
}
127129

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

134136
void runE2eTests() {
135-
sh '''
136-
make e2e-test
137-
'''
137+
sh """
138+
make e2e-test IMG=${operatorRepo}:${VERSION}
139+
"""
138140
}
139141

140142
void runMinikubeCleanup() {
@@ -146,6 +148,36 @@ 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+
branchNameTag = env.BRANCH_NAME.replaceAll('/', '-')
161+
sh """
162+
# make sure to logout first to avoid issues with cached credentials
163+
docker logout ${operatorRegistry}
164+
echo "${docker_password}" | docker login --username ${docker_user} --password-stdin ${operatorRegistry}
165+
166+
# Create tags
167+
docker tag ${operatorRepo}:${VERSION} ${operatorRegistry}/${operatorRepo}:${VERSION}
168+
docker tag ${operatorRepo}:${VERSION} ${operatorRegistry}/${operatorRepo}:${VERSION}-${branchNameTag}
169+
docker tag ${operatorRepo}:${VERSION} ${operatorRegistry}/${operatorRepo}:${VERSION}-${branchNameTag}-${timeStamp}
170+
docker tag ${operatorRepo}:${VERSION} ${operatorRegistry}/${operatorRepo}:latest
171+
172+
# Push images to internal registry
173+
docker push ${operatorRegistry}/${operatorRepo}:${VERSION}
174+
docker push ${operatorRegistry}/${operatorRepo}:${VERSION}-${branchNameTag}
175+
docker push ${operatorRegistry}/${operatorRepo}:${VERSION}-${branchNameTag}-${timeStamp}
176+
docker push ${operatorRegistry}/${operatorRepo}:latest
177+
"""
178+
}
179+
}
180+
149181
pipeline {
150182
agent {
151183
label {
@@ -157,16 +189,17 @@ pipeline {
157189
buildDiscarder logRotator(artifactDaysToKeepStr: '20', artifactNumToKeepStr: '', daysToKeepStr: '30', numToKeepStr: '')
158190
skipStagesAfterUnstable()
159191
}
160-
// triggers {
161-
// //TODO: add scheduled runs
162-
// }
163-
// environment {
164-
// //TODO
165-
// }
192+
193+
triggers {
194+
// Trigger nightly builds on the develop branch
195+
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
196+
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''' : '')
197+
}
166198

167199
parameters {
168200
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)
201+
string(name: 'VERSION', defaultValue: '1.1.0', description: 'Version to tag the image with.', trim: true)
202+
booleanParam(name: 'PUBLISH_IMAGE', defaultValue: false, description: 'Publish image to internal registry')
170203
string(name: 'emailList', defaultValue: emailList, description: 'List of email for build notification', trim: true)
171204
}
172205

@@ -206,6 +239,19 @@ 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+
}
209255

210256
}
211257

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ OPERATOR_SDK_VERSION ?= v1.34.2
6666
# Image URL to use all building/pushing image targets
6767
# Image for dev: ml-marklogic-operator-dev.bed-artifactory.bedford.progress.com/marklogic-operator-kubernetes
6868
# IMG ?= progressofficial/marklogic-operator-kubernetes:$(VERSION)
69-
IMG = "testrepo/marklogic-operator-image-dev:1.0.0"
69+
IMG ?= "testrepo/marklogic-operator-image-dev:1.0.0"
7070

7171

7272
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)

0 commit comments

Comments
 (0)