-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
executable file
·77 lines (74 loc) · 4.17 KB
/
Jenkinsfile
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
@Library('apim-jenkins-lib@master') _
pipeline {
agent { label "default" }
environment {
ARTIFACTORY_DOCKER_SBO_IMAGE_REG = "sbo-saas-docker-release-local.usw1.packages.broadcom.com"
ARTIFACTORY_DOCKER_GO_IMAGE_REG = "docker-hub.usw1.packages.broadcom.com"
ARTIFACTORY_DOCKER_DEV_LOCAL_REG_HOST = "apim-docker-dev-local.usw1.packages.broadcom.com"
ARTIFACT_HOST = "${ARTIFACTORY_DOCKER_DEV_LOCAL_REG_HOST}"
ARTIFACTORY_DOCKER_DEV_LOCAL_REG_PROJECT = "apim-gateway"
IMAGE_NAME = "layer7-operator"
IMAGE_TAG_BASE = "${ARTIFACTORY_DOCKER_DEV_LOCAL_REG_PROJECT}/${IMAGE_NAME}"
ARTIFACTORY_CREDS = credentials('ARTIFACTORY_USERNAME_TOKEN')
DOCKER_HUB_CREDS = credentials('DOCKERHUB_USERNAME_PASSWORD_RW')
def CREATED = sh(script: "echo `date -u +%Y-%m-%dT%H:%M:%SZ`", returnStdout: true).trim()
def YEAR = sh(script: "echo `date +%Y`", returnStdout: true).trim()
VERSION = "${env.BRANCH_NAME}"
COPYRIGHT = "Copyright ${YEAR} Broadcom Inc. and/or its subsidiaries. All Rights Reserved."
GOPROXY = ""
}
parameters {
string(name: 'RELEASE_VERSION', description: 'release version for docker tag')
}
stages {
stage('Build and Push Image') {
steps {
withCredentials([
usernamePassword(credentialsId: 'ARTIFACTORY_USERNAME_TOKEN', usernameVariable: 'ARTIFACTORY_DEV_LOCAL_USERNAME', passwordVariable: 'ARTIFACTORY_DEV_LOCAL_APIKEY')
]){
sh '''
if [[ -z "${RELEASE_VERSION}" ]]; then
if [[ "${BRANCH_NAME}" = "develop" ]]; then
export IMAGE_TAG="latest"
else
export RELEASE_VERSION="${BRANCH_NAME}"
fi
fi
GOPROXY="https://${ARTIFACTORY_DEV_LOCAL_USERNAME}:${ARTIFACTORY_DEV_LOCAL_APIKEY}@usw1.packages.broadcom.com/artifactory/api/go/apim-golang-virtual"
docker login ${ARTIFACTORY_DOCKER_DEV_LOCAL_REG_HOST} -u ${ARTIFACTORY_DEV_LOCAL_USERNAME} -p ${ARTIFACTORY_DEV_LOCAL_APIKEY}
docker login ${ARTIFACTORY_DOCKER_SBO_IMAGE_REG} -u ${ARTIFACTORY_DEV_LOCAL_USERNAME} -p ${ARTIFACTORY_DEV_LOCAL_APIKEY}
docker login ${ARTIFACTORY_DOCKER_GO_IMAGE_REG} -u ${ARTIFACTORY_DEV_LOCAL_USERNAME} -p ${ARTIFACTORY_DEV_LOCAL_APIKEY}
DISTROLESS_IMG=${ARTIFACTORY_DOCKER_SBO_IMAGE_REG}/broadcom-images/approved/distroless/static:debian12-nonroot
GO_BUILD_IMG=${ARTIFACTORY_DOCKER_GO_IMAGE_REG}/golang:1.23
cat Dockerfile | sed -e "s~DISTROLESS_IMG~${DISTROLESS_IMG}~g" | sed -e "s~GO_BUILD_IMG~${GO_BUILD_IMG}~g" > operator.Dockerfile
docker build -f operator.Dockerfile -t ${ARTIFACTORY_DOCKER_DEV_LOCAL_REG_HOST}/${IMAGE_TAG_BASE}:${RELEASE_VERSION} . --build-arg TITLE="${IMAGE_NAME}" --build-arg COPYRIGHT="${COPYRIGHT}" --build-arg VERSION="${RELEASE_VERSION}" --build-arg CREATED="${CREATED}" --build-arg GOPROXY="${GOPROXY}"
docker push ${ARTIFACTORY_DOCKER_DEV_LOCAL_REG_HOST}/${IMAGE_TAG_BASE}:${RELEASE_VERSION}
'''
}
}
}
}
post {
success {
script {
// send commit status to repo when the build is a pull request
if (env.CHANGE_ID) {
pullRequest.createStatus(status: 'success',
context: 'continuous-integration/jenkins/pr-merge',
description: 'Build Success',
targetUrl: "${env.JOB_URL}/testResults")
}
}
}
failure {
script {
if (env.CHANGE_ID) {
pullRequest.createStatus(status: 'failure',
context: 'continuous-integration/jenkins/pr-merge',
description: 'Build Failed',
targetUrl: "${env.JOB_URL}/testResults")
}
}
}
}
}