In this lab you will be connecting your Git repository with the Plants by WebSphere app to a Continuous Integration/Continuous Deployment pipeline built with Jenkins that will deploy to a IBM Cloud Kubernetes Service cluster.
If you haven't already:
-
Complete Part 1 - Working with Helm by following the instructions here
-
Initialize Helm client
helm init --client-only
-
Go to the folder where you cloned the Plants By WebSphere app in the previous lab
cd app-modernization-plants-by-websphere-jee6
In this section we will be connecting our cloned Git repo of this app to set up a Continuous Integration/Continuous Deployment pipeline built with Jenkins. This pipeline contains 4main steps as follows:
Stage | Purpose |
---|---|
Build Application ear File | Pulls in dependencies from Maven and packages application into .ear file |
Build Docker Image | Builds the Docker image based on the Dockerfile |
Push Docker Image to Registry | Uploads the Docker image to the Docker image registry within ICP |
Deploy New Docker Image | Updates the image tag in the Kubernetes deployment triggering a rolling update |
More details of this pipeline can be found in the Jenkinsfile.
-
Log into Jenkins using the URL provided to you by your instructor with the credentials provided to you
-
The pipeline should have already been created for you.
-
Click on your pipeline to open it and then click on the Configure link in the navigation area at the left to change it's properties
-
Scroll down to the Build Trigger section and select GitHub hook trigger for GIT SCM polling
-
Scroll down to the Pipeline section and find the Definition drop down menu. Select Pipeline script from SCM and for SCM select Git.
-
For Repository URL enter the url to the cloned repository that you forked earlier (i.e.
https://github.com/[your username]/app-modernization-plants-by-websphere-jee6.git
) -
Change the Script Path to
Jenkinsfile.ext
- Click Save.
-
In Jenkins in the navigation area on the left click on Build with Parameters. Accept the defaults of the parameters and click on Build
-
To see the console output click on the build number in the Build History and then click on Console Output
- If the build is successful the end of the console output should look like the following:
The Stage View of the pipeline should look like the following:
Now you'll configure Github to trigger your pipeline whenever code is committed.
-
Go back to Github and find your cloned repository
-
Click on the repository settings
- Under Options select Webhooks and click Add webhook
-
For the Payload URL use
<Jenkins URL>/github-webhook/
where<Jenkins URL>
is the URL you used to login to Jenkins (Note Don't forget the trailing/
) -
Change content type to application/json
-
Accept the other defaults and click Add webhook
-
In the Github file browser drill down to pbw-web/src/main/webapp/promo.xhtml
-
Click on the pencil icon to edit promo.xhtml and on line 95 locate the price of the Bonsai Tree
-
Change
$30.00 each
to<strike>$30.00</strike> $25.00 each
This will show the price of the Bonsai Tree as being reduced even more
-
At the bottom of the UI window add a commit message and click on Commit changes
-
Switch back to Jenkins and open the pipeline that you were working on earlier.
-
Verify that your pipeline starts building.
-
When the pipeline is finish deploying, launch the app to verify the change you made.
14.Run the following command to get the port number of your deployed app
kubectl --namespace default get service pbw-liberty-mariadb-liberty -o jsonpath='{.spec.ports[0].nodePort}'
- Run the following command to get the external IP address of the first worker node in your cluster
If you don't have the $USERNAME environment variable in the command set, replace $USERNAME with your lab user id.
ibmcloud cs workers $USERNAME-cluster | grep -v '^*' | egrep -v "(ID|OK)" | awk '{print $2;}' | head -n1
-
Your app's URL is the IP address of the first worker node with the port number of the deployed app. For example if your external IP is 169.61.73.182 and the port is 30961 the URL will be
http://169.61.73.182:30961
-
Enter the URL in hr browser's address bar and verify that the price of the Bonsai tree has been reduced.
Free up resources for subsequent labs by deleting the Plants by Websphere app.
-
Run the following command to delete the app
helm delete --purge pbw-liberty-mariadb
You created a Jenkins pipeline to automatically build and deploy an app that has been updated in Github .