-
Notifications
You must be signed in to change notification settings - Fork 572
/
Copy pathJenkinsfile.rh
62 lines (57 loc) · 2.02 KB
/
Jenkinsfile.rh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Copyright (c) 2016-present Sonatype, Inc. All rights reserved.
* Includes the third-party code listed at http://links.sonatype.com/products/nexus/attributions.
* "Sonatype" is a trademark of Sonatype, Inc.
*/
@Library(['private-pipeline-library', 'jenkins-shared']) _
properties([
parameters([
string(name: 'version', description: 'Version tag to apply to the image, like 3.41.0-ubi-1.'),
]),
])
node('ubuntu-zion') {
try {
stage('Preparation') {
deleteDir()
checkout scm
sh 'docker system prune -a -f'
sh '''
wget -q -O preflight \
https://github.com/redhat-openshift-ecosystem/openshift-preflight/releases/download/1.10.2/preflight-linux-amd64
chmod 755 preflight
'''
}
stage('Build') {
withCredentials([
usernamePassword(
credentialsId: 'red-hat-quay-nexus-repository-manager',
usernameVariable: 'REGISTRY_LOGIN',
passwordVariable: 'REGISTRY_PASSWORD'),
string(
credentialsId: 'red-hat-api-token',
variable: 'API_TOKEN')
]) {
def dockerfilePath = 'Dockerfile.rh.ubi.java17'
def baseImage = extractBaseImage(dockerfilePath)
def baseImageRefFactory = load 'scripts/BaseImageReference.groovy'
def baseImageReference = baseImageRefFactory.build(this, baseImage as String)
def baseImageReferenceStr = baseImageReference.getReference()
def buildRedhatImageShCmd = 'PATH="$PATH:." VERSION=$version ' +
"DOCKERFILE='${dockerfilePath}' " +
"BASE_IMG_REF='${baseImageReferenceStr}' " +
'./build_red_hat_image.sh'
sh buildRedhatImageShCmd
}
}
} finally {
sh 'docker logout'
sh 'docker system prune -a -f'
sh 'git clean -f && git reset --hard origin/main'
}
}
def extractBaseImage (dockerFileLocation) {
def dockerFile = readFile(file: dockerFileLocation)
def baseImageRegex = "FROM\\s+([^\\s]+)"
def usedImages = dockerFile =~ baseImageRegex
return usedImages[0][1]
}