Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Generate and save an HTML report in Jenkins on OpenShift 4

March 30, 2022
Muhammad Edwin
Related topics:
CI/CD
Related products:
Red Hat OpenShift

Share:

     

    Jenkins is one of the most popular CI/CD tools for automating builds and deployments. It is very flexible and can be deployed on almost every operating system, as well as on Red Hat OpenShift. This article shows you how to deploy Jenkins on OpenShift 4.9, create a simple pipeline to deploy a Java application to OpenShift, do some testing, save the test results as HTML, and publish it as an artifact so that people can see the results.

    For this scenario, we'll generate an HTML report using Maven OWASP Dependency Check plugins. The report will contain a list of libraries that contain vulnerabilities. This pipeline runs on Jenkins 2.2 on top of OpenShift 4.9.

    Use Jenkins to generate a report on OpenShift 4

    There are multiple ways to set up Jenkins on OpenShift 4. This article uses a template provided by the OpenShift Developer Catalog.

    First, check whether the Jenkins template is available in OpenShift:

    $ oc get template -n openshift | grep jenkins

    If Jenkins templates are available, you'll get output such as:

    jenkins-ephemeral                               Jenkins service, without persistent storage....                                    8 (all set)       7
    
    jenkins-ephemeral-monitored                     Jenkins service, without persistent storage. ...                                   9 (all set)       8
    
    jenkins-persistent                              Jenkins service, with persistent storage....                                       10 (all set)      8
    
    jenkins-persistent-monitored                    Jenkins service, with persistent storage. ...                                      11 (all set)      9

    Now let's try to spawn a Jenkins ephemeral report. In this case, ephemeral means that the service is not storing its data. The ephemeral approach is good for a nonproduction environment. The following command creates Jenkins instances in the CI/CD namespace:

    $ oc new-app --template=jenkins-ephemeral -n cicd

    Check the created route to see the exact URL for the newly created Jenkins instances. Then open that URL and log in with your OpenShift credentials.

    Building and running a pipeline

    Start creating a build pipeline by selecting a Pipeline icon in your Jenkins instance, as shown in Figure 1.

    Screenshow showing how to create a Pipeline in the Jenkins console.
    Figure 1: Create a Pipeline in the Jenkins console.

    Next, paste the following code into the Pipeline script, as shown in Figure 2:

    node('maven') {
    
        stage ('pull code') {
    
            sh "git clone https://github.com/edwin/hello-world-java-docker.git source"
    
        }
    
        stage ('build') {
    
            dir("source") {
    
                sh "mvn -Dmaven.repo.local=/tmp/m2 org.owasp:dependency-check-maven:check"
    
            }
    
        }
    
    	stage ('generate report') {
    
            dir("source") {
    
              publishHTML (target: [
    
                  allowMissing: true,
    
                  alwaysLinkToLastBuild: true,
    
                  keepAll: true,
    
                  reportDir: 'target',
    
                  reportFiles: 'dependency-check-report.html',
    
                  reportName: "Application-Dependency-Check-Report"
    
                ])
    
            }
    
        }
    
    }
    Screenshow showing the script being inserted into a Pipeline script.
    Figure 2: The script should be inserted into a Pipeline Script.

    Now focus on the "generate report" stage, where you save your HTML report as a build artifact. Press the Build Now button, highlighted in Figure 3, to trigger the pipeline.

    Screenshow showin ghow the Pipeline's web page lets you build the Pipeline.
    Figure 3: The Pipeline's web page lets you build the Pipeline.

    And now the HTML report appears in the menu bar on the left, as shown in Figure 4.

    Screenshot showing that a report appears in the menu of the Pipeline web page.
    Figure 4: A report appears in the menu of the Pipeline web page.

    Clicking on the report button displays the contents of the generated HTML report, as illustrated in Figure 5.

    Screenshot of a formatted report displayed on the web page.
    Figure 5: A formatted report is displayed on the web page.

    If you find that your report shows some errors or is a bit disorganized, there's a workaround to fix it. Go to Script Console inside the Manage Jenkins menu, as shown in Figure 6.

    Screenshot showing that the Script Console is available in Tools and Actions.
    Figure 6: The Script Console is available in Tools and Actions.

    Type the following script inside the Script Console text field and then press the Run button.

    System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")

    Conclusion

    In addition to automating your CI/CD process, Jenkins can automate the recording of events that occur during its own run. This article has illustrated several parts of the open source environment that make it easy to generate and save reports from Jenkins.

    Last updated: September 20, 2023

    Recent Posts

    • How to use RHEL 10 as a WSL Podman machine

    • MINC: Fast, local Kubernetes with Podman Desktop & MicroShift

    • How to stay informed with Red Hat status notifications

    • Getting started with RHEL on WSL

    • llm-d: Kubernetes-native distributed inferencing

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue