From 5fc721dbd79fed45a51b59b31439528a8a89d7de Mon Sep 17 00:00:00 2001 From: Jakub Filipczak Date: Thu, 10 Nov 2022 11:40:04 +0100 Subject: [PATCH 1/2] Replace git-plugin with git clone for helm steps in Jenkinsfile --- Jenkinsfile | 85 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d77f59c..0051f50 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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" } @@ -86,7 +86,7 @@ pipeline { } } - // ๐Ÿ’ฅ๐Ÿ”จ PIPELINE EXERCISE GOES HERE + // ๐Ÿ’ฅ๐Ÿ”จ PIPELINE EXERCISE GOES HERE stage("๐Ÿง Bake (OpenShift Build)") { options { @@ -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 ###' @@ -117,38 +117,46 @@ 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 + ''' + 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 + ''' + } } } @@ -158,7 +166,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") )} @@ -174,6 +182,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") } } @@ -183,7 +194,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}") @@ -236,22 +247,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 } } From 734d557fb1093e255d6f2b5b21ed8ea66d518d9e Mon Sep 17 00:00:00 2001 From: Jakub Filipczak Date: Thu, 10 Nov 2022 11:53:40 +0100 Subject: [PATCH 2/2] add explicit checkout to branch --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0051f50..978a9e2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -122,7 +122,8 @@ pipeline { } steps { sh ''' - git clone ${GIT_URL} pet-battle + git clone ${GIT_URL} pet-battle && cd pet-battle + git checkout ${BRANCH_NAME} ''' dir('pet-battle'){ echo '### Lint Helm Chart ###'