0

I want to design a Jenkins job that will trigger when a pull request is created and perform a static code analysis only on the java files that have been modified.

I've already created a Jenkins job that is triggered on pushes and scans a repository for 1 error by following this video and cloning his repository to my bitbucket: https://www.youtube.com/watch?v=aRgYd-SLyrs. So far the job only works on the App.java file but I want it to work on only the files being pull requested. Has anyone done anything like this? I'm in the beginning stages so any kind of guidance will help.

  • 1
    Have you tried just get the list of changed files (addressed here https://stackoverflow.com/questions/424071/how-to-list-all-the-files-in-a-commit) and remove the rest ? Not sure if the code analysis will work reliably on an incomplete project. – Rostislav Matl Aug 07 '19 at 15:53

1 Answers1

0

This basically depends on the tool you are using for the static analysis of the code. I can propose a plan which you have to implement in Jenkins.

  1. Identify the files changed in the most recent commit. Use git diff --name-only HEAD HEAD~1

  2. Invoke your static analysis tool in such a way it scans only the files identified in the 1st step. There should be a way to pass this information to your tool via command line.

warunanc
  • 2,221
  • 1
  • 23
  • 40
  • Im trying to edit the job to implement your idea which I think will work. I'm confused about how a Jenkins job knows what files to act on. Is there a file or something I can edit that will tell the job where to get those files? – Jeffrey Samson Aug 08 '19 at 19:05