In this exercise we will explore the CloudBees Core Cross Team Collaboration feature. Cross Team Collaboration simplifies the cumbersome and complicated tasks of triggering downstream jobs by eliminating the need to identify and maintain the full path for every downstream job. Simply put it, this proprietary feature connects pipelines, increasing automation and collaboration. Prior to this feature, the details of every downstream job (Jenkins instance ID, full job name, Git branch name) all had to meticulously specified in the upstream job. If the job name changed, the upstream job had to be refactored, creating a maintenance burden and discouraging the adoption of event-based triggers.
The Cross Team Collaboration feature is designed to greatly improve team collaboration by connecting team Pipelines to deliver software faster. It essentially allows a Pipeline to create a notification event which will be consumed by other Pipelines waiting on it. It consists of a Publishing Event and a Trigger Condition.
The Cross Team Collaboration feature has a configurable router for routing events and it needs to be configured on your Team Master before you will be able to receive the event published by another Team Master. Once again, CasC was used to pre-configure this for everyone, but you can still check it by going to the top-level of your Team Master in the classic UI, clicking on Manage Jenkins and then clicking on Configure Notification - you should see the following configured:
- Now our pipeline must must be updated to listen for a hello-api-deploy-event event. We will do that by adding a
trigger
to your Jenkinsfile Pipeline script. - Open the GitHub editor for the Jenkinsfile file in the master branch of your forked helloworld-nodejs repository.
- Add the following
trigger
block just above the top-levelstages
block:
triggers {
eventTrigger simpleMatch('hello-api-deploy-event')
}
- Commit the changes and then navigate to the master branch of your helloworld-nodejs job in Blue Ocean on your Team Master.
**NOTE:**After first adding a new
trigger
you must run the job at least once so that thetrigger
is saved to the Jenkins job configuration (similar to what was necessary for thebuildDiscarder
option
earlier).
Now I will set up a Multibranch Pipeline project for the https://github.com/cloudbees-days/helloworld-api repository and add the following simple event to the Deploy stage of the helloworld-api Jenkinsfile
:
publishEvent simpleEvent('hello-api-deploy-event')
That event will be published across all Team Masters in our Workshop cluster via the CloudBees Operations Center event router causing everyones' helloworld-nodejs Pipelines to be triggered.
Now I, once I commit that change, and run the helloworld-api job and everyone should see the master branch of their helloworld-nodejs job triggered.
Before moving on to the next lesson make sure that your Jenkinsfile Pipeline script on the master branch of your forked helloworld-nodejs repository matches the one from below.
pipeline {
agent none
options {
buildDiscarder(logRotator(numToKeepStr: '2'))
skipDefaultCheckout true
}
triggers {
eventTrigger simpleMatch('hello-api-deploy-event')
}
stages {
stage('Test') {
agent {
kubernetes {
label 'nodejs-app-pod-2'
yamlFile 'nodejs-pod.yaml'
}
}
steps {
checkout scm
container('nodejs') {
echo 'Hello World!'
sh 'node --version'
}
}
}
stage('Build and Push Image') {
when {
beforeAgent true
branch 'master'
}
steps {
echo "TODO - build and push image"
}
}
}
}
You may proceed to the next lab Lab 7. Pipeline with Interactive Input or head back to the main list of the labs when you are ready.