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

Initial ci pipeline workshop #80

Merged
merged 47 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
17ced9c
initil ci pipeline workshop
Mar 3, 2021
a3b3d58
updated submodule for ci pipeline workshop
Mar 3, 2021
4dff940
updated submodule for ci pipeline workshop
Mar 3, 2021
94be98d
removed unneeded stuff
Mar 3, 2021
eb09b57
fix labs index page
Mar 3, 2021
932baf9
tweaks
Mar 3, 2021
db58b20
first updates for declarative basics lab
Mar 4, 2021
bc4a804
updates for declarative basics
Mar 6, 2021
5f45b44
updates for declarative basics
Mar 6, 2021
fd70410
updates for Stage Specific Agents lab
Mar 6, 2021
c9222bb
conditial lab updates
Mar 6, 2021
5a03a69
moved image folders
Mar 6, 2021
8a6e932
fix image for stage agents lab
Mar 6, 2021
0ea7439
conditial lab updates
Mar 6, 2021
6b00c59
updated pod template lab
Mar 7, 2021
119312f
update pipeline workshop
Mar 9, 2021
bc74075
remove home link from menu
Mar 15, 2021
3455300
updated screenshots
Mar 16, 2021
f3c3af8
fixing merge conflict
Mar 17, 2021
f37d091
added/fixed screenshots, update Jenkinsfile
Mar 17, 2021
99d5ce9
added/fixed screenshots, fixed test lab
Mar 17, 2021
2830e3b
misc updates; added env credentials lab
Mar 17, 2021
6f7cd38
updated declarative lab
Mar 17, 2021
53edb27
udpated order
Mar 17, 2021
16c8cd3
fixed typo; updated some screenshots
Mar 18, 2021
7de1e53
misc tweaks
Mar 18, 2021
a9a278f
misc tweaks
Mar 18, 2021
cde94a1
added nested stage, when not
Mar 19, 2021
64e52ae
added nested stage, when not
Mar 19, 2021
abe3f5d
tweaks for custom pod template lab
Mar 19, 2021
7f2f34e
tweaks for custom pod template lab
Mar 19, 2021
044ce41
tweaks for environment lab
Mar 19, 2021
8189c80
tweaks for environment lab
Mar 19, 2021
9fc5ef9
tweaks for environment lab
Mar 19, 2021
d77c13c
tweaks for environment lab
Mar 19, 2021
527e9c7
tweaks for environment lab
Mar 20, 2021
e51f610
updated collab lab
Mar 20, 2021
470df58
updated input lab
Mar 20, 2021
7482b71
updated input lab
Mar 20, 2021
ecdea46
updated input lab
Mar 21, 2021
8ea242b
updated input lab
Mar 21, 2021
3ee2f97
mis tweaks
Mar 21, 2021
7966f50
mis tweaks
Mar 21, 2021
6dd56e2
misc tweaks
Mar 22, 2021
76558b3
misc tweaks
Mar 22, 2021
94e4493
misc tweaks
Mar 22, 2021
2f0b9d8
misc tweaks
Mar 22, 2021
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "labs/base/themes/hugo-theme-learn"]
path = labs/base/themes/hugo-theme-learn
url = https://github.com/matcornic/hugo-theme-learn.git
[submodule "labs/cloudbees-ci-pipeline/themes/hugo-theme-learn"]
path = labs/cloudbees-ci-pipeline/themes/hugo-theme-learn
url = https://github.com/matcornic/hugo-theme-learn/tree/3efb32712c5cc77e644852d13ce3525780374b10
1 change: 1 addition & 0 deletions labs/base/content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ weight: 1
# CloudBees Field Workshops

[CloudBees CI Workshop](/cloubees-ci/)
[CloudBees CI Pipeline Workshop](/cloubees-ci-pipeline/)
[CloudBees Feature Flags Workshop](/cloubees-feature-flags/)
25 changes: 25 additions & 0 deletions labs/cloudbees-ci-pipeline/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
baseURL = ""
languageCode = "en-US"
defaultContentLanguage = "en"

title = "CloudBees CI Pipeline Workshop"
theme = "hugo-theme-learn"
metaDataFormat = "yaml"

[outputs]
home = [ "HTML", "RSS", "JSON"]

[params]
# Change default color scheme with a variant one. Can be "red", "blue", "green".
themeVariant = "cloudbees"
editURL = "https://github.com/cloudbees-days/cloudbees-field-workshops/edit/main/labs/cloudbees-ci-pipeline/content/"
# Shows a checkmark for visited pages on the menu
showVisitedLinks = true
# Set this to true to disable copy-to-clipboard button for inline code.
disableInlineCopyToClipBoard = true
disableLandingPageButton = true

[markup]
[markup.goldmark]
[markup.goldmark.renderer]
unsafe = true
18 changes: 18 additions & 0 deletions labs/cloudbees-ci-pipeline/content/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: "CloudBees CI Pipeline Workshop"
chapter: true
weight: 1
---

# CloudBees CI Pipeline Workshop

This workshop will provide a basic understanding of how to create and manage Jenkins CI/CD Declarative Pipelines leveraging developer focused features of CloudBees CI.

This repository contains instructions and learning materials for the workshop that is designed to teach the following key concepts:

* How specific features of CloudBees CI on Kubernetes will accelerate your continuous delivery?
* Why you should *mostly* use [Declarative](https://jenkins.io/doc/book/pipeline/syntax/#declarative-pipeline) vs [Scripted](https://jenkins.io/doc/book/pipeline/syntax/#scripted-pipeline) pipelines?
* How reusable templates for Jenkins Declarative Pipelines can increase developer productivity?
* What are the key features of Declarative Pipelines?

#### <a href="https://cloudbees-days.github.io/cloudbees-field-workshops/cloudbees-ci-pipeline/">CloudBees CI Pipeline Workshop Slides</a>
9 changes: 9 additions & 0 deletions labs/cloudbees-ci-pipeline/content/getting-started/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "Getting Started"
chapter: true
weight: 1
---

# Getting Started

In order to complete the labs in this workshop you will need to have a personal GitHub Organization with the [CloudBees CI Pipeline Workshop GitHub App](https://github.com/apps/cloudbees-ci-pipeline-workshop) installed on it. Also, by completing the GitHub components of the workshop setup before the workshop we will be able to focus on the content covered in this workshop.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: "CloudBees CI Login"
chapter: false
weight: 3
---

CloudBees CI for modern platforms takes advantage of Kubernetes to providing dynamic provisioning of team specific Jenkins instances we refer to as ***managed controllers***. In this lab you will provision a CloudBees ***managed controller*** (Jenkins instance) with an initial configuration provided by CloudBees CI Configuration-as-Code.

>NOTE: If you haven't already received the link for the CloudBees CI Workshop cluster, then ask your instructor for it.

## CloudBees CI Managed Controller

### Login to CloudBees CI

1. Login into the CloudBees CI Workshop cluster at: [https://cbci.workshop.cb-sa.io/cjoc/login](https://cbci.workshop.cb-sa.io/cjoc/login)
2. Enter the username and password, provided by your instructor, into the login screen and click the **Sign in** button. ![CloudBees CI Login](setup-login.png?width=40pc)
3. Click on the link of your CloudBees CI ***managed controller*** that will have the same name (lowercased) as the GitHub Organization you are using for this workshop. ![managed controller link](managed-controller-link.png?width=70pc)
4. NOTE: Depending on when you completed the pre-workshop setup your ***managed controller*** may still be **Starting** as seen below. ![managed controller starting](starting.png?width=60pc)
If that is the case you will have to wait until it is **Approved** and **Connected** as seen in the following screenshot. Once the **Status** is **Approved** and **Connected** click on the link for your managed controller. ![managed controller connnected](mc-connected.png?width=60pc)

>NOTE: There are a number of ways to create a ***managed controller***. We take a very opinionated way to provision attendees ***managed controllers*** for this workshop in order to pre-configure the components that you will interact with during the workshop, allowing us to jump into the hands on content more quickly.

**For instructor led workshops please <a href="https://cloudbees-days.github.io/cloudbees-field-workshops/cloudbees-ci/#cbci-setup-review">return to the workshop slides</a>**
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: "Pre-Workshop Setup"
chapter: false
weight: 2
---
#### <i class="fas fa-clock"></i> The pre-workshop setup should take you approximately 10 minutes to complete.

If you are attending a CloudBees led workshop then these setup steps should be completed before the start of the workshop event.

## GitHub Setup

### Create a github.com Account

Feel free to use an existing github.com account or create a new one:
1. In a new browser tab or window, visit [https://github.com/join](https://github.com/join) and fill in the required fields to create a github.com user account.
2. Select "Unlimited public repositories for free" when choosing your plan.
3. Verify your email account to ensure you account is activated. An activated account will be **required** for the rest of this workshop.

### Create a GitHub Organization

We highly recommend creating a new GitHub Organization for the CloudBees CI Pipeline Workshop. We will be using a GitHub App based credential to enable authentication and authorization between your github.com Organization for the workshop and CloudBees CI.
1. Ensure that you are logged into github.com and then navigate to this [link to create a new (and free) GitHub Organization](https://github.com/account/organizations/new?coupon=&plan=team_free).
2. Enter a unique ***Organization account name***, a valid ***Contact email***, select **My personal account** for ***This organization belongs to*** and then click on the **Next** button.<p>![GitHub Org Set up](github-org-set-up.png?width=40pc)
3. On the **Welcome to GitHub** screen just click the **Complete setup** button.<p>![GitHub Org Set up](github-org-welcome.png?width=50pc)
4. On the final page you don't have to fill anything in/answer any questions (unless your really want to) and just scroll to the bottom of the page and click the **Submit** button.

>NOTE: Even though you have to provide an email for billing, **you will NOT be charged anything** as long as you choose the free option.

### Install the CloudBees CI Pipeline Workshop GitHub App

1. Ensure that you are logged into github.com and then navigate to [https://github.com/apps/cloudbees-ci-pipeline-workshop](https://github.com/apps/cloudbees-ci-pipeline-workshop).<p>![GitHub App](cbci-pipeline-github-app.png?width=60pc)
2. Click on the **Install** button.
3. Next, select the GitHub Organization you created above for the CloudBees CI Pipeline Workshop.<p>![GitHub App](github-app-select-org.png?width=50pc)
4. On the next screen, select **All repositories** and click the **Install** button.<p>![GitHub App](github-app-install.png?width=50pc)
5. You may be prompted for your GitHub password. Enter your github.com password, for the GitHub account you are using for this workshop, to complete the installation of the CloudBees CI Workshop GitHub App into your workshop specific GitHub Organization.
6. The CloudBees CI Pipeline Workshop GitHub App is now installed on your workshop GitHub Organization. <p>![GitHub App Installed](installed-now.png?width=50pc)
7. A few minutes after you install the CloudBees CI Workshop GitHub App you should see the following repositories created in your workshop GitHub Organization.
- https://github.com/cloudbees-days/cloudbees-ci-config-bundle
- https://github.com/cloudbees-days/pipeline-library
- https://github.com/cloudbees-days/pipeline-template-catalog
- https://github.com/cloudbees-days/node-js ![GitHub App Installed](forked-repos.png?width=50pc)

>NOTE: These repositories were created from GitHub template repositories in the [CloudBees Field Workshops GitHub Organization](https://github.com/cloudbees-days).

**For instructor led workshops please <a href="https://cloudbees-days.github.io/cloudbees-field-workshops/cloudbees-ci/#core-overview-title">return to the workshop slides</a>**
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: "Prerequisites"
chapter: false
weight: 1
---

* Internet access to include access to [https://github.com](https://github.com) and to include the ability to access and use the [GitHub File Editor](https://help.github.com/articles/editing-files-in-your-repository).
* Access to https://app.slack.com
* An account on [https://github.com](https://github.com) and a basic understanding of how to use GitHub to edit files in the web UI, and create and work with pull requests. If you are new to GitHub or just new to using GitHub pull requests then you should review [this GitHub documentation](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/proposing-changes-to-your-work-with-pull-requests) before the workshop.
* A basic understanding of [Jenkins Pipelines](https://jenkins.io/doc/book/pipeline/getting-started/)
* A basic understanding of [Kubernetes](https://kubernetes.io/docs/tutorials/kubernetes-basics/)
* Understand the concept of a [Kubernetes Pod](https://kubernetes.io/docs/concepts/workloads/pods/) and how it is different than a Docker container
* Finally, we highly recommend using the Google Chrome browser to work through the lab content.

21 changes: 21 additions & 0 deletions labs/cloudbees-ci-pipeline/content/labs/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: "Labs"
chapter: true
weight: 1
---

# Labs

This workshop will provide a basic understanding of how to create and manage Jenkins CI/CD Declarative Pipelines while leveraging some of the developer focused features of CloudBees CI.

The labs covered in this workshop are:

1. Introduction to Declarative Pipelines with CloudBees CI
2. Stage Specific Agents
3. Custom Pipeline Pod Templates
4. Conditional Execution Using the `when` Directive
5. Environment Variables and Credentials
6. CloudBees Cross Team Collaboration
7. Pipelines with Interactive Input
8. CloudBees Pipeline Template Catalogs

41 changes: 41 additions & 0 deletions labs/cloudbees-ci-pipeline/content/labs/catalog-templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: "CloudBees Pipeline Template Catalogs"
chapter: false
weight: 8
---

Pipeline Template Catalogs provide version controlled parameterized templates for Multi-branch and stand-alone Pipeline jobs. In this exercise we will use [Pipeline Template Catalogs](https://github.com/cloudbees-days/pipeline-template-catalog/tree/master/templates/nodejs-app) to create a templatized Multibranch Pipeline project of your workshop copy of the **helloworld-nodejs** repository. All you will need to do is fill in a few simple parameters and you will end up with a complete end-to-end CI/CD Pipeline for the **helloworld-nodejs** application - and it won't be using the `Jenkinsfile` from your repository.

## Create a Multibranch Project from a Pipeline Template Catalog
[Jenkins Configurations as Code](https://wiki.jenkins.io/display/JENKINS/Configuration+as+Code+Plugin) (JCasC) was used to pre-configure a Pipeline Template Catalog on everyone's Managed Controller and there is a **template-jobs** folder on your Managed Controller that has been configured with [CloudBees Folders Plus folder item filtering](https://go.cloudbees.com/docs/plugins/folders-plus/#folders-plus-sect-restrict) to only allow the creation of certain job types. Now we will create a templatized end-to-end CI/CD Pipeline Multibranch project for your copy of the **helloworld-nodejs** repository.

1. On your CloudBees CI Managed Controller navigate to the **template-jobs** folder and then lick on the ***New Node.js App Multibranch Pipeline*** link in the left menu. ![Create Job from Template](create-template-job-link.png?width=50pc)
2. Enter an item name of your **[GitHub username]-hello**, select **Node.js App Multibranch Pipeline** and click the **OK** button. ![New Item Form](new-item-form.png?width=50pc)
3. Fill out the template parameters:
1. **Repository Owner**: the GitHub Organization your created for the CloudBees CI Pipeline Workshop.
2. Use the default values for the rest of the parameters.
3. Click the **Save** button. ![Template Parameters](template-parameters.png?width=50pc)
4. The initial scan won't find any branches because you have to add the [custom markerfile](https://go.cloudbees.com/docs/cloudbees-core/cloud-admin-guide/pipeline/#_multibranch_pipeline_options_in_template_yaml) `.nodejs-app` to any branch that you want a job to be created. The [template we are using has a markerFile parameter set to .nodejs-app](https://github.com/cloudbees-days/pipeline-template-catalog/blob/master/templates/nodejs-app/template.yaml#L29), so we need to add that file to at least one branch of your copy of the **helloworld-nodejs** repository.
5. Make sure you are on the **development** branch and click on the **Create new file** button towards the top right of the screen.
6. Name the file `.nodejs-app` and commit the empty file to your **development** branch.
7. You may need to refresh the Multibranch job screen, but you should eventually have **one** job - for the **development** branch. ![One Job](one-job.png?width=50pc)

## Web Browser Tests with Testcafe

Executing [Testcafe](http://devexpress.github.io/testcafe/) driven browser tests for the **helloworld-nodejs** app in our Pipeline.

1. After you add the custom marker file, your **development** branch job will run and it will fail. On the job details screen for the failed run we can see that there was a test failure. Click on the **Test Result** link to see the specific test error. ![Job Details Failed Test](job-details-failed-test.png?width=50pc)
2. On the **Test Result** page, expand the **Initial page.Check message header** test and then expand the **Stack Trace** and you will see that there is a slight typo in the **helloworld-nodejs** app. ![Test Results Failure](test-results-failure.png?width=50pc)
3. In GitHub, open editor for the `hello.js` file on the **development** branch of your forked copy of the **helloworld-nodejs** repository, fix the misspelling of **Worlld** to **World** and then commit the changes. ![Fix Error](fix-error.png?width=50pc)
4. Navigate to the **development** branch of your **helloworld-nodejs** job on your Managed Controller and your job should already be running as a GitHub webhook triggered it when you committed the changes for the `hello.js` file in the **helloworld-nodejs** repository. The tests should pass and the job should complete successfully. ![Test Passed](test-passed.png?width=50pc)

## Deploy to Staging
Now that you have fixed the small bug in the **helloworld-nodejs** application, we will create a Pull Request and merge the change to the **main** branch of your copy of the **helloworld-nodejs** repository.

1. Navigate to your copy of the **helloworld-nodejs** repository in GitHub - click on the **New pull request** button. ![Test Passed](new-pull-request.png?width=50pc)
2. On the next screen add a comment and then click the **Create pull request** button.
3. A job will be created for the pull request and once it has completed successfully your pull request will show that **All checks have passed**. Go ahead and click the **Merge pull request** button and then click the **Confirm merge** button but **DO NOT DELETE** the **development** branch. ![Merge PR](merge-pr.png?width=50pc)
4. Navigate to the **helloworld-nodejs** Pipeline Template Catalog job on your Managed Controller and the job for the **main** branch should be running or queued to run.
5. The templated job will build a Docker image for your **helloworld-nodejs** application, push the image to the Google Container Registry (GCR), and then deploy your containerized application to a staging environment in Kubernetes - a link to your application will be available in the logs of your job. All of this after only filling in a few parameters to create the job in CloudBees CI.


Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading