Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 14 additions & 4 deletions docs/2-attack-of-the-pipelines/3a-jenkins.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Jenkins Pipeline

> Jenkins is a tool that's been around for sometime but it's stuck with a lot of customers. It's a build server that's pretty dumb by nature but can be enhanced with lots of plugins and agents which is why it's such a powerful tool.
> Jenkins is a tool that's been around for sometime but it's stuck with a lot of customers. It's a build server that's pretty dumb by nature but can be enhanced with lots of plugins and agents which is why it's such a powerful tool.

<!---
#### Jenkins access to GitLab
Expand Down Expand Up @@ -50,7 +50,7 @@ git push
echo "https://$(oc get route jenkins --template='{{ .spec.host }}' -n ${TEAM_NAME}-ci-cd)/multibranch-webhook-trigger/invoke?token=pet-battle"
```

Once you have the URL, over on GitLab go to `pet-battle > Settings > Integrations` to add the webhook
Once you have the URL, over on GitLab go to `pet-battle > Settings > Integrations` to add the webhook
![gitlab-webhook-trigger-fe.png](./images/gitlab-webhook-trigger-fe.png)

#### Jenkins Pipeline
Expand Down Expand Up @@ -142,10 +142,19 @@ git push
6. Now that we've gone through what this stuff does, let's try fix the failing build. If you look at the output of the Jenkins job, you'll see it's not able to find anything in Nexus to put in a container. To fix this, update the `Jenkinsfile` by adding a new `stage` which will run app compilation, producing the artifact in Nexus for us. Add the following below to the `// 💥🔨 PIPELINE EXERCISE GOES HERE ` comment:

```groovy
// 💥🔨 PIPELINE EXERCISE GOES HERE
// 💥🔨 PIPELINE EXERCISE GOES HERE
stage("🧰 Build (Compile App)") {
agent { label "jenkins-agent-npm" }
options {
skipDefaultCheckout(true)
}
steps {
sh '''
git clone ${GIT_URL} pet-battle && cd pet-battle
git checkout ${BRANCH_NAME}
'''
dir('pet-battle'){

script {
env.VERSION = sh(returnStdout: true, script: "npm run version --silent").trim()
env.PACKAGE = "${APP_NAME}-${VERSION}.tar.gz"
Expand All @@ -164,7 +173,7 @@ git push
echo '### Running build ###'
sh 'npm run build '

// 🌞 SONARQUBE SCANNING EXERCISE GOES HERE
// 🌞 SONARQUBE SCANNING EXERCISE GOES HERE
echo '### Running SonarQube ###'

echo '### Packaging App for Nexus ###'
Expand All @@ -173,6 +182,7 @@ git push
curl -v -f -u ${NEXUS_CREDS} --upload-file ${PACKAGE} \
http://nexus:8081/repository/${NEXUS_REPO_NAME}/${APP_NAME}/${PACKAGE}
'''
}
}
// 📰 Post steps go here
}
Expand Down
51 changes: 36 additions & 15 deletions tests/doc-regression-test-files/3a-jenkins-Jenkinsfile.groovy
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,10 +86,18 @@ pipeline {
}
}

// 💥🔨 PIPELINE EXERCISE GOES HERE
// 💥🔨 PIPELINE EXERCISE GOES HERE
stage("🧰 Build (Compile App)") {
agent { label "jenkins-agent-npm" }
options {
skipDefaultCheckout(true)
}
steps {
sh '''
git clone ${GIT_URL} pet-battle && cd pet-battle
git checkout ${BRANCH_NAME}
'''
dir('pet-battle'){
script {
env.VERSION = sh(returnStdout: true, script: "npm run version --silent").trim()
env.PACKAGE = "${APP_NAME}-${VERSION}.tar.gz"
Expand All @@ -108,7 +116,7 @@ pipeline {
echo '### Running build ###'
sh 'npm run build '

// 🌞 SONARQUBE SCANNING EXERCISE GOES HERE
// 🌞 SONARQUBE SCANNING EXERCISE GOES HERE
echo '### Running SonarQube ###'

echo '### Packaging App for Nexus ###'
Expand All @@ -117,6 +125,7 @@ pipeline {
curl -v -f -u ${NEXUS_CREDS} --upload-file ${PACKAGE} \
http://nexus:8081/repository/${NEXUS_REPO_NAME}/${APP_NAME}/${PACKAGE}
'''
}
}
// 📰 Post steps go here
}
Expand All @@ -132,7 +141,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 @@ -150,7 +159,15 @@ pipeline {

stage("🏗️ Deploy - Helm Package") {
agent { label "jenkins-agent-helm" }
options {
skipDefaultCheckout(true)
}
steps {
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 '

Expand All @@ -167,21 +184,22 @@ pipeline {

# 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}
# 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 @@ -191,7 +209,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 @@ -207,6 +225,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 @@ -216,7 +237,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 @@ -269,22 +290,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

}
}
}