如何使用与詹金斯

问题描述:

集成的Python API脚本我有使用Python API如下触发ZAP创建ZAP HTML报告(OWASP): -如何使用与詹金斯

脚本来源: -

https://github.com/zaproxy/zaproxy/wiki/ApiPython

我希望通过命令行生成HTML报告。

我正在尝试与Jenkins进行整合。 我在Jenkins中发现了Owasp的一些插件,但似乎没有按预期工作。

任何想法,链接,教程将真的帮助我。

+0

的http://本地主机:8080 /其它/ core/other/htmlreport /?apikey = mykey&formMethod = GET将显示报告。但如何保存并发送与詹金斯指: - https://github.com/zaproxy/zaproxy/issues/2920 –

在此URL/API(http://ZAP-IP:PORT/UI/core/other/htmlreport/)用户可以获取报告。

我没有找到任何zap支持插件,所以我写了selenium webdriver java脚本来完成我的任务。该代码是: -

@Test 
    public void Report() { 
      System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir")+"\\src\\lib\\chromedriver.exe"); 
      ChromeOptions chromeOptions = new ChromeOptions(); 
      chromeOptions.addArguments("--start-maximized"); 
      WebDriver driver = new ChromeDriver(chromeOptions); 
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
      driver.get("http://localhost:8080/UI/core/other/htmlreport"); 
      driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); 
      driver.findElement(By.id("apikey")).sendKeys("ChangeMe"); 
      driver.findElement(By.id("button")).click(); 

      SimpleDateFormat dateFormatForFoldername = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); 
      Date currentDate = new Date(); 
      String folderDateFormat = dateFormatForFoldername.format(currentDate); 
     try { 
      URL oracle = new URL(driver.getCurrentUrl()); 
      BufferedReader in = new BufferedReader(
      new InputStreamReader(oracle.openStream())); 
      BufferedWriter writer = new BufferedWriter(new FileWriter("Reports"+File.separator+"OwaspReport-"+folderDateFormat+".html")); 

      String inputLine; 
      while ((inputLine = in.readLine()) != null){ 
       try{ 
        writer.write(inputLine); 
       } 
       catch(IOException e){ 
        e.printStackTrace(); 
        return; 
       } 
      } 
      in.close(); 
      writer.close(); 
      driver.quit(); 
     } 
     catch(Exception ex) { 
      System.out.println(ex.getMessage()); 
      ex.printStackTrace(); 
     } 
    } 

注: - 更改URL中的端口,按您的ZAP端口和更换apiKey

希望它会帮助你:)

我发现了Python API会只连接到本地zaproxy服务器,所以jenkins slave和zaproxy服务器应该在同一台机器(pod)中运行。

我使用jenkins管道和publishHTML插件来将报告集成到jenkins结果中。

  1. 由python脚本

    fHTML=open('/zap/report/zapreport.html', 'w') 
    fHTML.write(zap.core.htmlreport()) 
    fHTML.close() 
    
  2. 产生詹金斯子机侧的报告文件发布报告,詹金斯导致

     sh "cp /zap/report/* ./report" 
         publishHTML (target: [ 
         allowMissing: false, 
         alwaysLinkToLastBuild: false, 
         keepAll: true, 
         reportDir: 'report', 
         reportFiles: 'zapreport.html', 
         reportName: "Zaproxy Report" 
         ])