Working with Artifacts and Fingerprints

Hands-On Lab

 

Photo of Michael McClaren

Michael McClaren

Linux Training Architect I in Content

Length

01:00:00

Difficulty

Intermediate

In this hands-on lab, we will be looking at working with artifacts and fingerprints. We will install the copy artifact plugin, and we will pass artifacts between jobs. This will allow us to chain builds to segment the build process. This is needed to prevent overrun where a team that feeds a section of the pipeline has access to another area that is not under their direct scope.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Working with Artifacts and Fingerprints

Introduction

In this hands-on lab, we will be looking at working with artifacts and fingerprints. We will install the "copy artifact" plugin, and then we will pass artifacts between jobs.

Solution

To access the lab environment, log in as cloud_user, using the public IP address and login information provided in the Credentials section of the hands-on lab page.

Create the webdev Folder and the index Project

  1. Once logged in to the Jenkins Dashboard, click Manage Jenkins.

  2. Click Global Tool Configuration.

  3. Scroll down, and click Add Maven.

  4. In the Name field type M3 for our instance configuration of Maven.

  5. Click Save.

  6. Navigate back to dashboard for Jenkins.

  7. Click New Item.

  8. In the Enter an item name field, create a folder named webdev.

  9. Ensure that Folder is selected.

  10. Click Ok.

  11. Accept the defauls and click Save.

  12. Look at the top breadcrumb navigation menu, to ensure that we're in the webdev folder.

  13. Click Create a new jobs.

  14. Inside the webdev folder make a freestyle project named index.

  15. Ensure that Freestyle project is selected.

  16. Click Ok.

  17. Click the Source Code Management tab.

  18. Click the radio button for Git.

  19. In the Repository URL section, copy/paste the following link: https://github.com/linuxacademy/content-cje-prebuild.git

    Note: Click outside the field to remove any red text.

  20. Click the Build tab.

  21. Under the Build section, select Invoke top-level Maven targets.

  22. For the Maven Version enter M3.

  23. For Goals input clean package.

  24. Under the Execute shell section and in the Command field input bin/makeindex.

  25. Under the Post-Build section, select Archive the artifacts.

  26. In the Files to archive field, input index.jsp.

  27. Click the Advanced... button and ensure that the radio button for Fingerprint all archived artifacts is also selected.

  28. Click Save.

  29. From the Project index file page, click Build Now on the left-hand side navigation menu.

  30. Refresh the page, then click view for the index.jsp.

    Note: We should see e.g. 'Hello the Tomcat server is running!'

Install the Copy Artifact Plugin

  1. Navigate to the main page Jenkins > Manage Jenkins > ManagePlugins
  2. Click the Available tab.
  3. Search for copy artifact in the upper-right hand side Filter field.
  4. Click the radio button for Copy Artifact.
  5. Click Download now and install after restart.
  6. Click Restart Jenkins when installation is complete and no jobs are running.
  7. Wait for Jenkins to restart.

    Note: We may need to refresh and sign back in as student.

Create and Build the tomcat Project

  1. Navigate back to the main page for Jenkins.

  2. Click New Item.

  3. In the Enter an item name field_ input backend.

  4. Ensure that Folder is selected.

  5. Click OK.

  6. Accept the defaults and click Save.

  7. Ensure that we're on the backend folder via the breadcrumb navigation menu, then click on New Item.

  8. In the Enter an item name field, input tomcat.

  9. Ensure that Folder is selected.

  10. Click OK.

  11. Click the Source Code Management tab.

  12. Click the radio button for Git.

  13. Copy/paste the following: https://github/com/linuxacademy/content-jenkinscert.git in the Repository URL field.

    Note: Click outside the field to remove any red text.

    The first build step should be copying the artifact from the webdev/index job to src/main/webapp in the tomcat job.

  14. From the Build tab, click Add build steps > Copy artifacts from another project.

  15. For the Project name input webdev/index.

  16. For the Artifacts to copy field input index.jsp.

  17. For the Target directory field input src/main/webapp in the tomcat job.

  18. Click Add build step > Invoke top-level Maven targets.

  19. For the Maven Version enter M3.

  20. For Goals input clean package.

  21. Under the Post-Build Actions section, and Test report XMLs field type target/surefire-reports/*.xml

  22. Click Save.

  23. Click Build Now.

  24. We can then view the test results and our tomcat project. From the Workspace of tomcat on master , we can click src > main > webapp and view to verify the index.jsp copied the message correctly.

    Note: It may take a minute for the test results to generate.

Conclusion

Congratulations - you've completed this hands-on lab!