Hi,
I have a demo setup on my local workstation where i have installed Jenkins and have integrated it with GIT.Â
Basically i am trying to run the ZAP spider and scanner against a local website on my localhost whenever a code submit happens.
I have the GIT part and Jenkins working and i use the build-zap.xml noted below:
<project name="zap" default="wave-test" basedir=".">
    <description>Build ZAP.</description>
    <!-- set global properties for this build -->
    <property name="src" location="/home/usmanw/ZAP_2.1.0" />
    <property name="dist" location="/home/usmanw/ZAP_2.1.0" />
    <!--
    In Eclipse you can get these taskdefs to work by adding the following jars to the 'Ant Home Entries'.
    To get there: Windows / Preferences / Ant / Runtime
    TODO: Work out how this should be done properly and document ;)
    lib/json-lib-2.4-jdk15.jar
    lib/commons-lang-2.6.jar
    lib/commons-logging-1.1.1.jar
    lib/commons-collections-3.2.1.jar
    lib/commons-beanutils-1.8.3.jar
    lib/ezmorph-1.0.6.jar
    build/zap/zap-api.jar (after you've run the dist target in build.xml)
    -->
    <taskdef name="accessUrlTask" classname="org.zaproxy.clientapi.ant.AccessUrlTask"/>
    <taskdef name="activeScanUrlTask" classname="org.zaproxy.clientapi.ant.ActiveScanUrlTask"/>
    <taskdef name="activeScanSiteTask" classname="org.zaproxy.clientapi.ant.ActiveScanSiteTask"/>
    <taskdef name="alertCheckTask" classname="org.zaproxy.clientapi.ant.AlertCheckTask"/>
    <taskdef name="loadSessionTask" classname="org.zaproxy.clientapi.ant.LoadSessionTask"/>
    <taskdef name="newSessionTask" classname="org.zaproxy.clientapi.ant.NewSessionTask"/>
    <taskdef name="saveSessionTask" classname="org.zaproxy.clientapi.ant.SaveSessionTask"/>
    <taskdef name="spiderUrlTask" classname="org.zaproxy.clientapi.ant.SpiderUrlTask"/>
    <taskdef name="stopZapTask" classname="org.zaproxy.clientapi.ant.StopZapTask"/>
    <taskdef name="alert" classname="org.zaproxy.clientapi.ant.AlertTask"/>
    <!--
    These settings are for ZAP installed in the standard location on a Windows machine
    listenning on localhost:8090 and
    testing the ZAP Web App Vulnerability Examples running on localhost:8080
    -->
    <property name="targetApp" value="${targetHost}"/>
    <property name="zapaddr" value="localhost" />
    <property name="zapport" value="8090" />
    <property name="zapdir" value="/home/usmanw/ZAP_2.1.0" />
<target name="startZap">
        <java classname="org.zaproxy.zap.ZAP" fork="true" spawn="true" dir="${zapdir}">
            <classpath>
                <pathelement location="${zapdir}/zap.jar"/>
            </classpath>
        </java>
        <!-- Give ZAP a chance to start -->
        <sleep seconds="20"/>
    </target>
    <target name="startZapDaemon">
        <java classname="org.zaproxy.zap.ZAP" fork="true" spawn="true" dir="${zapdir}">
            <arg value="-daemon"/>
            <classpath>
                <pathelement location="${zapdir}/zap.jar"/>
            </classpath>
        </java>
        <!-- Give ZAP a chance to start -->
        <sleep seconds="20"/>
    </target>
    <target name="stopZap">
      <stopZapTask zapAddress="${zapaddr}" zapPort="${zapport}" debug="true"/>
    </target>
    <target name="spider">
      <spiderUrlTask zapAddress="${zapaddr}" zapPort="${zapport}" url="${targetHost}"/>
    </target>
    <target name="activescanSite">
      <activeScanSiteTask zapAddress="${zapaddr}" zapPort="${zapport}" url="${targetHost}"/>
    </target>
  <target name="activescanUrl">
    <activeScanUrlTask zapAddress="${zapaddr}" zapPort="${zapport}" url="${targetHost}"/>
  </target>
    <target name="wave-test">
        <!-- Start ZAP -->
        <antcall target="startZapDaemon" />
        <!-- Access the top URL -->
      <accessUrlTask zapAddress="${zapaddr}" zapPort="${zapport}" url="${targetApp}" debug="true"/>
        <!-- Spider the whole site -->
      <spiderUrlTask zapAddress="${zapaddr}" zapPort="${zapport}" url="${targetHost}" debug="true"/>
        <sleep seconds="5"/>
        <!-- Need to Spider again - and need to investigate why this is required ;) -->
      <spiderUrlTask zapAddress="${zapaddr}" zapPort="${zapport}" url="${targetHost}" debug="true"/>
        <sleep seconds="5"/>
        <!-- Active scan the whole site -->
      <activeScanUrlTask zapAddress="${zapaddr}" zapPort="${zapport}" url="${targetHost}" debug="true"/>
        <sleep seconds="5"/>
        <!-- Save to a timestamped session file -->
        <tstamp>
            <format property="timestamp" pattern="MM-dd-yyyy-HH-mm-ss"/>
        </tstamp>
      <saveSessionTask zapAddress="${zapaddr}" zapPort="${zapport}" name="usmantest-${timestamp}" debug="true"/>
        <!-- Give the passive scanner thread a chance to catch up -->
        <sleep seconds="20"/>
        <!-- Stop ZAP -->
      <stopZapTask zapAddress="${zapaddr}" zapPort="${zapport}"/>
    </target>
</project>
When i run the build-zap.xml file using ant from the command line everything works fine. I get an ERROR message when it runs within Jenkins.
The error message is noted below:
Started by user usman waheed
Building in workspace /var/lib/jenkins/workspace/Test1
Checkout:Test1 / /var/lib/jenkins/workspace/Test1 - hudson.remoting.LocalChannel@6b29745b
Using strategy: Default
Last Built Revision: Revision 9313c9d48c8eb33feda6f49cac16659b391ff16c (origin/master, origin/HEAD)
Fetching changes from 1 remote Git repository
Fetching upstream changes from origin
Seen branch in repository origin/HEAD
Seen branch in repository origin/master
Seen 2 remote branches
Commencing build of Revision 9313c9d48c8eb33feda6f49cac16659b391ff16c (origin/master, origin/HEAD)
Checking out Revision 9313c9d48c8eb33feda6f49cac16659b391ff16c (origin/master, origin/HEAD)
Warning : There are multiple branch changesets here
[tools] $ ant -file build-zap.xml -lib /home/usmanw/ZAP_2.1.0/zap.jar -lib /home/usmanw/ZAP_2.1.0/zap-api-v2-2.jar
Buildfile: /home/usmanw/tools/build-zap.xml
wave-test:
startZapDaemon:
BUILD FAILED
/home/usmanw/tools/build-zap.xml:93: org.zaproxy.clientapi.core.ClientApiException: java.net.ConnectException: Connection refused
at org.zaproxy.clientapi.core.ClientApi.accessUrlViaProxy(Unknown Source)
at org.zaproxy.clientapi.core.ClientApi.accessUrl(Unknown Source)
at org.zaproxy.clientapi.ant.AccessUrlTask.execute(Unknown Source)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
at sun.net.www.http.HttpClient$1.run(HttpClient.java:430)
at sun.net.www.http.HttpClient$1.run(HttpClient.java:428)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.http.HttpClient.privilegedOpenServer(HttpClient.java:427)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:468)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:974)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)
... 19 more
Total time: 20 seconds
Build step 'Invoke Ant' marked build as failure
Finished: FAILURE
I though this might have to do with permissions but that does not seem to be the case. Has anyone using Jenkins run into this error and if clues would be appreciated.Â
If you have more questions please let me know and i can share more info on what i have done so far.
Thanks and Regards,
Usman
Â