I have integrated Jenkins with PMD checksytle for Apex.


<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">


<property file="build.properties"/>
<property environment="env"/>

<!-- Setting default value for username, password and session id properties to empty string 
     so unset values are treated as empty. Without this, ant expressions such as ${sf.username}
     will be treated literally.
<condition property="sf.username" value=""> <not> <isset property="sf.username"/> </not> </condition>
<condition property="sf.password" value=""> <not> <isset property="sf.password"/> </not> </condition>
<condition property="sf.sessionId" value=""> <not> <isset property="sf.sessionId"/> </not> </condition>

<target name="runRuleTest" depends="PMDTest">

<taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
        <pathelement location="../ant-salesforce.jar" />            

<!-- Retrieve the contents into another directory -->
<target name="PMDTest">
  <!-- Retrieve the contents listed in the file codepkg/package.xml into the codepkg directory -->
           <sf:retrieve username="${sf.username}" password="${sf.password}" 
                serverurl="${sf.serverurl}" retrieveTarget="C:\Jenkins\pmd-bin-5.8.0-SNAPSHOT\pmd-bin-5.8.0-SNAPSHOT\Sample" unpackaged="C:\Jenkins\pmd-bin-5.8.0-SNAPSHOT\pmd-bin-5.8.0-SNAPSHOT\Sample\package.xml"/>

PMD is integrated to run as a post build action as follows:

pmd.bat -rulesets C:\Jenkins\pmd-bin-5.8.0-SNAPSHOT\pmd-bin-5.8.0-SNAPSHOT\rules\ApexRules.xml -d C:\Jenkins\pmd-bin-5.8.0-SNAPSHOT\pmd-bin-5.8.0-SNAPSHOT\Sample\classes

My problem: The retrieve line in build.xml retrieves all the classes in the org. I would like to only retrieve files which are changed in git. For eg: if we change something in Sample.cls then rather that retrieving all the classes, i would like to retrieve only the full Sample.cls so that the PMD checkstyle should only run on the changed files. Is this possible?

  • Maybe you can give a try to use Salesforce Migration Assistant plugin. It says "This Jenkins plugin automatically deploys metadata changes to a Salesforce organization based on differences between two commits in Git. Instead of deploying a repository's contents every time a change is made, the plugin can determine what metadata needs to be deployed and deleted and coordinate only those changes." github.com/jenkinsci/salesforce-migration-assistant-plugin/wiki – Saroj Bera Jun 12 '17 at 13:19
  • I dont want to deploy changes. I want to retrieve the files and run PMD apex code analyser on it. – Nagendra Singh Jun 12 '17 at 14:42
  • 1
    I highly recommend you to ask your questions at the PMD Github repos: github.com/pmd/pmd/issues. Apex is just a language module of a larger open-source project with a very big and helpful community. As your problem is not really Salesforce-specific I expect you to get help there much faster. – Robert Sösemann Oct 19 '17 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.