In this exercise we are going to update our pipeline to demonstrate how Checkpoints work and how end users can interact with Checkpoints once a job as been built.
- Add the following stage before
stage('Testing')
:
stage('Checkpoint') {
agent none
steps {
checkpoint 'Checkpoint'
}
}
- Save & Run your pipeline.
- When the
input
step from the Testing stage asks to Deploy or Abort - select Abort - The UI to interact with a
checkpoint
is not availbe in Blue Ocean so you will need to exit to the classic Jenkins UI for the next step. - When the job has completed running you will see a Resume icon in the build's Stage View. Clicking on the Resume icon gives you the ability to:
-
- Delete - Delete the cached artifacts and configuration for that build;
-
- Restart - Restart the build from the checkpoint.
- Click Restart and your pipeline will run from your
checkpoint
forward - skipping over the Say Hello stage - When the
input
step from the Testing stage asks to Deploy or Abort - select Testing
NOTE: Deleting a checkpoint doesn't make the Resume icon vanish.
In this exercise we are going to set-up two Pipeline jobs (using the Jenkins classic UI) that demonstrate CloudBee's Cross Team Collaboration feature. We will need two separate Pipelines - one that publishes an event - and another that is triggered by an event.
For the first part of Cross Team Collaboration we will create an event that is only published on your master.
First you have to publish an event from a Pipeline - any other Pipeline may set a trigger to listen for this event. Create a Pipeline job named notify-event
with the following content:
pipeline {
agent none
stages {
stage('Publish Event') {
steps {
publishEvent simpleEvent('beeEvent')
}
}
}
}
Replace beeEvent
with your {username}Event
so my event would be beedemo-devEvent
.
Next, create a Pipeline job name notify-trigger
and set a trigger
to listen for the event you created above with the following content:
pipeline {
agent none
triggers {
eventTrigger simpleMatch('beeEvent')
}
stages {
stage('Event Trigger') {
when {
expression {
return currentBuild.rawBuild.getCause(com.cloudbees.jenkins.plugins.pipeline.events.EventTriggerCause)
}
}
steps {
echo 'triggered by published event'
}
}
}
}
After creating both of these Pipeline jobs you will need to run the Event Trigger job once so that the trigger is registered (similar to what was necessary for job parameters). Once that is complete, click on Build Now to run the Publish Event job. Once that job has completed, the Event Trigger job will be triggered after a few seconds. The logs will show that the job was triggered by an Event Trigger
and the when
expression will be true.
For the second part of Cross Team Collaboration we will create an event that will be published across Team Masters via CloudBees Operations Center. The Cross Team Collaboration feature has a configurable router for routing events and we will change the router used for this exercise. You will need to select a partner to work with - one person will be the notifier and the other person will update their event-trigger job to be triggered when the notifier's job is run.
- First you need to update the Notification Router Implementation to use the Operations Center Messaging router by clicking on the Manage Jenkins link - on the left side at the root of your Team Master (classic ui).
- Next, scroll down and click on Configure Notification link.
- Under Notification Router Implementation select the Operations Center Messaging option as opposed to the currently selected Local only option.
- Now, the trigger job of the second partner needs to be updated to listen for the notifier's
event
string - ask your partner what their event string is - and then run the job once to register the trigger. - Next, the notifier will run their
notify-event
job and you will see thenotify-trigger
job get triggered.
In this exercise we will get an introduction to the Jenkins Kubernetes plugin and use the container
block to run a set of steps inside a Docker container set-up in a Jenkins Kubernetes Agent template. So far we have used different labels
to specify different JDK versions. But now we want to use Maven and our Jenkins Administrator has confifured a Jenkins Kubernetes plugin template to include access to a maven container.
- Replace the Testing stage with the following stage:
stage('Testing') {
parallel {
stage('Java 7') {
agent { label 'jdk7' }
steps {
container('maven') {
sh 'mvn -v'
}
}
}
stage('Java 8') {
agent { label 'jdk8' }
steps {
container('maven') {
sh 'mvn -v'
}
}
}
}
}
- Save & Run your pipeline.
- Compare the logs for the Java 7 and Jave 8 stages.
In this exercise we are going to create a Jenkins GitHub Organization project from a newly forked repository and the repository you created in Setup - Create a GitHub Organization.
First, let's add your GitHub credentials to the Jenkins' Credentials manager:
- Navigate back to your personal folder in Jenkins
- Click on Credentials
- Click on [YourFolderName] under Stores Scoped to [YourFolderName]
- Click on Global Credentials (Unrestricted)
- Click on Add Credentials
- Fill out the form (Username with password)
- Username: The Github organization name
- Password: Your Github personal access token
- ID: Create an ID for your credentials (something like yourorg-id)
- Description: Can be left blank if you want
- Click on OK
Now let's create the Github Organization project:
- Click on New Item
- Enter your organization name as the Item Name
- Select GitHub Organization
- Click Ok
- Select the credentials you created above from the Credentials drop down
- Select All from the Strategy drop down under Discover Branches
- Click Save
Once you click on save, Jenkins will search your organization for any projects with Jenkinsfiles in them, import those projects as Multibranch projects, and begin building each branch with a Jenkinsfile in it.
When the project was created it also should have created a webhook in Github. Verify that the webhooks were created in Github by checking Webhooks within your Organization's Github Settings.
In the following exercise we are going to demonstrate how you can use the Custom Marker feature of CloudBees Jenkins Enterprise to assign pipeline to a job based on an arbitrary file name like pom.xml.
In order to complete the following exercise you will need to fork the following repository into the Github Organization you created in Setup - Create a GitHub Organization:
Once that repository is forked:
- Click on the Github organization project you created in the GitHub Organization Project exercise.
- Click on Configure
- Under Project Recognizers select Custom Script
- In Marker file type
pom.xml
- Under Pipeline - Definition select Pipeline script from SCM
- Select Git from SCM
- In Repository URL enter:
https://github.com/PipelineHandsOn/custom-marker-files
- Select your credentials from the Credentials menu
- In Script path enter:
Jenkins-pom
- Click on Save
- Click on Scan Organization Now
When the scan is complete your Github Organization project should now have both the sample-rest-server project and the maven-project.
You may move onto Distributed Pipelines with Pipeline As Code once your instructor tells you to.