Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace git-plugin with git clone for helm steps in Jenkinsfile #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 49 additions & 37 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pipeline {
GIT_CREDS = credentials("${OPENSHIFT_BUILD_NAMESPACE}-git-auth")
NEXUS_CREDS = credentials("${OPENSHIFT_BUILD_NAMESPACE}-nexus-password")

// Nexus Artifact repo
// Nexus Artifact repo
NEXUS_REPO_NAME="labs-static"
NEXUS_REPO_HELM = "helm-charts"
}
Expand Down Expand Up @@ -86,7 +86,7 @@ pipeline {
}
}

// 💥🔨 PIPELINE EXERCISE GOES HERE
// 💥🔨 PIPELINE EXERCISE GOES HERE

stage("🧁 Bake (OpenShift Build)") {
options {
Expand All @@ -99,7 +99,7 @@ pipeline {
sh '''
rm -rf package-contents*
curl -v -f -u ${NEXUS_CREDS} http://nexus:8081/repository/${NEXUS_REPO_NAME}/${APP_NAME}/${PACKAGE} -o ${PACKAGE}
# clean up
# clean up
oc delete bc/${APP_NAME} is/${APP_NAME} || rc=$?
'''
echo '### Run OpenShift Build ###'
Expand All @@ -117,38 +117,47 @@ pipeline {

stage("🏗️ Deploy - Helm Package") {
agent { label "jenkins-agent-helm" }
options {
skipDefaultCheckout(true)
}
steps {
echo '### Lint Helm Chart ###'
sh 'helm lint chart '
sh '''
git clone ${GIT_URL} pet-battle && cd pet-battle
git checkout ${BRANCH_NAME}
'''
dir('pet-battle'){
echo '### Lint Helm Chart ###'
sh 'helm lint chart '

// Kube-linter step
echo '### Kube Lint ###'
// Kube-linter step
echo '### Kube Lint ###'

echo '### Patch Helm Chart ###'
script {
env.CHART_VERSION = sh(returnStdout: true, script: "yq eval .version chart/Chart.yaml").trim()
}
sh '''
# might be overkill...
yq eval -i .appVersion=\\"${VERSION}\\" "chart/Chart.yaml"
echo '### Patch Helm Chart ###'
script {
env.CHART_VERSION = sh(returnStdout: true, script: "yq eval .version chart/Chart.yaml").trim()
}
sh '''
# might be overkill...
yq eval -i .appVersion=\\"${VERSION}\\" "chart/Chart.yaml"

# over write the chart name for features / sandbox dev
yq eval -i .name=\\"${APP_NAME}\\" "chart/Chart.yaml"

# probs point to the image inside ocp cluster or perhaps an external repo?
yq eval -i .image_repository=\\"${IMAGE_REPOSITORY}\\" "chart/values.yaml"
yq eval -i .image_name=\\"${APP_NAME}\\" "chart/values.yaml"
yq eval -i .image_namespace=\\"${IMAGE_NAMESPACE}\\" "chart/values.yaml"

# latest built image
yq eval -i .image_version=\\"${VERSION}\\" "chart/values.yaml"
'''
echo '### Publish Helm Chart ###'
sh '''
# package and release helm chart - could only do this if release candidate only
helm package --dependency-update chart/ --app-version ${VERSION}
curl -v -f -u ${NEXUS_CREDS} http://nexus:8081/repository/${NEXUS_REPO_HELM}/ --upload-file ${APP_NAME}-*.tgz
'''
# over write the chart name for features / sandbox dev
yq eval -i .name=\\"${APP_NAME}\\" "chart/Chart.yaml"

# probs point to the image inside ocp cluster or perhaps an external repo?
yq eval -i .image_repository=\\"${IMAGE_REPOSITORY}\\" "chart/values.yaml"
yq eval -i .image_name=\\"${APP_NAME}\\" "chart/values.yaml"
yq eval -i .image_namespace=\\"${IMAGE_NAMESPACE}\\" "chart/values.yaml"

# latest built image
yq eval -i .image_version=\\"${VERSION}\\" "chart/values.yaml"
'''
echo '### Publish Helm Chart ###'
sh '''
# package and release helm chart - could only do this if release candidate only
helm package --dependency-update chart/ --app-version ${VERSION}
curl -v -f -u ${NEXUS_CREDS} http://nexus:8081/repository/${NEXUS_REPO_HELM}/ --upload-file ${APP_NAME}-*.tgz
'''
}
}
}

Expand All @@ -158,7 +167,7 @@ pipeline {
stage("🏖️ Sandbox - Helm Install"){
options {
skipDefaultCheckout(true)
}
}
agent { label "jenkins-agent-helm" }
when {
expression { return !(GIT_BRANCH.startsWith("master") || GIT_BRANCH.startsWith("main") )}
Expand All @@ -174,6 +183,9 @@ pipeline {
}
stage("🧪 TestEnv - ArgoCD Git Commit") {
agent { label "jenkins-agent-argocd" }
options {
skipDefaultCheckout(true)
}
when {
expression { GIT_BRANCH.startsWith("master") || GIT_BRANCH.startsWith("main") }
}
Expand All @@ -183,7 +195,7 @@ pipeline {
git clone https://${GIT_CREDS}@${ARGOCD_CONFIG_REPO} config-repo
cd config-repo
git checkout ${ARGOCD_CONFIG_REPO_BRANCH} # master or main

PREVIOUS_VERSION=$(yq eval .applications.\\"${APP_NAME}\\".values.image_version "${ARGOCD_CONFIG_REPO_PATH}")
PREVIOUS_CHART_VERSION=$(yq eval .applications.\\"${APP_NAME}\\".source_ref "${ARGOCD_CONFIG_REPO_PATH}")

Expand Down Expand Up @@ -236,22 +248,22 @@ pipeline {
// stage("🥾 Trigger System Tests") {
// options {
// skipDefaultCheckout(true)
// }
// }
// agent { label "master" }
// when {
// expression { GIT_BRANCH.startsWith("master") || GIT_BRANCH.startsWith("main") }
// }
// steps {
// echo "TODO - Run tests"
// build job: "system-tests/main",
// build job: "system-tests/main",
// parameters: [[$class: 'StringParameterValue', name: 'APP_NAME', value: "${APP_NAME}" ],
// [$class: 'StringParameterValue', name: 'CHART_VERSION', value: "${CHART_VERSION}"],
// [$class: 'StringParameterValue', name: 'VERSION', value: "${VERSION}"]],
// [$class: 'StringParameterValue', name: 'VERSION', value: "${VERSION}"]],
// wait: false
// }
// }

// 💥🔨 BLUE / GREEN DEPLOYMENT GOES HERE
// 💥🔨 BLUE / GREEN DEPLOYMENT GOES HERE

}
}