Nexus Platform Plugin for Jenkins
- Reviewing Evaluation Results
- Evaluating Docker Images
- Example: Using the Results of a Policy Evaluation from a Pipeline Build
Sonatype Platform Plugin for Jenkins (previously known as the Nexus Platform Plugin for Jenkins) integrates Jenkins with Lifecycle and Nexus Repository.
- Perform SCA open-source evaluations during the application build
- Push the CI analysis back to to CSM pull request
- Publish build artifacts to Repo Manager 3
Installation
Installing the Plugin in the Jenkins UI
- Download the most recent Sonatype Platform Plugin from the downloads page
- Sign in to Jenkins as an administrator
- Navigate to the Manage Jenkins > Plugins page
- Click on the Advanced tab
- Choose the .hpi file you previously downloaded
- Optionally you may enter the URL to the archive file under the Deploy Plugin section
- Deploy the plugin
Install through the Jenkins Plugin Manager
Installing the plugin through the Jenkins Plugin Manager is not currently supported. Installing and upgrading should be done using the Jenkins UI or the Alternative Methods.
- Sign in to Jenkins as an administrator
- Navigate to the Manage Jenkins > Plugins page
- In the Plugin Manager window, select the Available tab and enter "Nexus Platform" in the Filter: search box
- Select the Install checkbox next to the Nexus Platform plugin
A message displays on the screen when the Sonatype Platform plugin has been successfully installed.
Install Using Alternative Methods
Sonatype Platform Plugin for Jenkins can be installed using the Jenkins CLI or advanced methods.
Java Version
The Sonatype Platform Plugin for Jenkins expects Java versions 8 or 11. Other versions are not supported.
HTTP Proxying
Sonatype Platform Plugin for Jenkins uses the HTTP proxy setting defined in Jenkins under Manage Jenkins > Manage Plugins > Advanced. To bypass the HTTP proxy server you must update the non-proxy host to include the IQ Server.
Configuration
Connecting Jenkins to the IQ Server
Jenkins can be configured to connect with one or more instances of IQ Server to use when evaluating your application builds. The first instance in the list is used by default.
The configured user for IQ Server must have the 'Evaluate Applications' permission for any applications to be evaluated. We recommend creating a Jenkins service account and using tokens to reduce the risk of exposing credentials.
- Sign in to Jenkins as an administrator
- Navigate to the Manage Jenkins > Configure System
- In the Sonatype section, select IQ Server from the Add IQ Server dropdown menu
- Display Name: The name used to select an IQ Server instance
- Server ID: ID to specify an IQ Server instance in pipeline builds
- Server URL: The location of the IQ Server
- Credentials: Enter the IQ Server username and password using the Jenkins Provider Credentials: Jenkins
- Select the credentials from the dropdown list and select 'Test Connection'
- The IQ report summary is embedded in Jenkins build reports. Optionally, select the 'Hide embedded reports in Jenkins' to only link to the report
- Select the Save button
Defining Sonatype Platform Plugin Build Steps
Pipeline refers to both Declarative and Scripted Jenkins Pipelines.
Project (or Job) refers to a Jenkins item, such as a Freestyle project, Multi-configuration project, or Maven project, that allows selecting an explicit build step from a drop-down menu and filling in form field values inside the build configuration.
The scan patterns supported by default are **/*.jar, **/*.war, **/*.ear, **/*.zip, **/*.tar.gz.
To use other patterns, a manual override of iqScanPatterns is required, as specified here.
The Step user interface is identical for Jenkins Projects Build configuration and Pipeline Snippet Generator. Use the available Step names for the latest version of the plugin listed on the Sonatype Platform Plugin Steps Reference page.
Defining Steps for Pipeline
- In the Pipeline section of a Pipeline project configuration screen, open the Snippet Generator by clicking the Pipeline Syntax link.
- In the Steps section of the Snippet Generator window, select one of the Sonatype Platform Plugin-defined steps.
- After filling in the step field values, you can copy the generated snippet into your pipeline script.
Defining Steps for Projects
- In the Build section of your project configuration screen, click the Add Build Step drop-down and select a Sonatype Platform Plugin step from the list.
- Fill in the step field values and save your project.
Adding an Evaluation to a Build
Invoking a Lifecycle Policy Evaluation
Adding Pipeline Build Step
Jenkins pipelines allow for a Lifecycle Policy Evaluation at any point during the build. This allows for a policy gate to be set anywhere along the build and delivery process.
Use the following steps to add a Lifecycle Policy Evaluation build step to a pipeline build:
- In the Pipeline section of the project configuration screen, click the Pipeline Syntax link.
- In the Steps section of the Snippet Generator window, select the following:
- Sample Step: Select nexusPolicyEvaluation: Invoke Lifecycle Policy Evaluation.
- IQ Instance: Select an IQ Server that will be used to run the policy evaluation.
Stage: Select Develop, Source, Build, Stage Release, Release, or Operate. This controls the stage the policy evaluation is run against on the IQ Server. Only the stages you are licensed to appear in the list. Depending on how your policies are configured in IQ Server, this may impact warning and fail actions.
Organization (optional): Select an organization from the list. If automatic application creation is enabled and the application does not exist, it will be created under the selected organization.
If both the application and the organization IDs are provided, and the application already exists under a different organization, the evaluation process stops with an error message. This mechanism is in place to prevent accidental configurations, which could unintentionally alter the evaluation history of existing applications.
- Application: Select an application from the list of available IQ Server applications. This determines the policy elements (policies, labels, and license threat groups) to associate with this build and is managed via the IQ Server. If automatic application creation is enabled, an application, that's not in the list can also be specified and an application with the specified ID will automatically be created in IQ Server.
Advanced options: See the Advanced Step Options for details of each option. Use the Jenkins Pipeline Snippet Generator to help generate supported advanced options for your current plugin version.
- Click the Generate Pipeline Script button.
Copy the generated script and paste it into the desired stage of your pipeline script.
Example Pipeline ScriptnexusPolicyEvaluation( iqApplication: 'SampApp', iqInstanceId: 'MyIQServer1', iqStage: 'build' )
Example Pipeline Script with Scan Patterns to Override Defaults
nexusPolicyEvaluation( iqApplication: 'SampApp', iqInstanceId: 'MyIQServer1', iqScanPatterns: [[scanPattern: '**/*.js'], [scanPattern: '**/*.zip']], iqStage: 'build', iqOrganization: '55040769ec08424e84049356a3362d07' )
Example Pipeline Script Overriding Most Advanced Options
nexusPolicyEvaluation( advancedProperties: 'test=value', enableDebugLogging: true, failBuildOnNetworkError: true, failBuildOnScanningErrors: true, iqApplication: selectedApplication('sandbox-application'), iqInstanceId: 'MyIQServer1', iqModuleExcludes: [[moduleExclude: '**/module-2-exclude/module.xml'], [moduleExclude: '**/module-1-exclude/module.xml']], iqScanPatterns: [[scanPattern: '**/other/*.jar'], [scanPattern: '**/special/*.jar']], iqStage: 'build', jobCredentialsId: 'iq-server-localhost' )
- Complete your pipeline build and click Save.
Adding Project Step
To add a Lifecycle Policy Evaluation build step to the project:
- In the Build section of the project configuration screen, click the Add Build Step dropdown button and then select Invoke Lifecycle Policy Evaluation.
- IQ Instance: Select an IQ Server that will be used to run the policy evaluation.
Stage: Select Develop, Source, Build, Stage Release, Release, or Operate. This controls the stage the policy evaluation is run against on the IQ Server. Only the stages enabled by your IQ Server license appear in the list.
Organization (optional): Select an organization from the list. If automatic application creation is enabled and the application does not exist, it will be created under the selected organization. If both the application and the organization IDs are provided, and the application already exists under a different organization, the evaluation process stops with an error message. This mechanism is in place to prevent accidental configurations, which could unintentionally alter the evaluation history of existing applications.
- Application: Select an application from the list of available IQ Server applications. This determines the policy elements (policies, labels, and license threat groups) to associate with this build and is managed via the IQ Server. An application can also be specified that is not on the list. If automatic application creation is enabled, an application with the specified ID will automatically be created if it does not already exist in the IQ Server.
- Advanced options: Click the Advanced button to view the advanced step options. Note that when using custom scan targets only one target is allowed per line.
- Complete the rest of your project configuration and click Save.
Reviewing the Evaluation Results
Once a specific build has successfully completed, a summary of the results is shown on the project screen. The three boxes (red, orange, and yellow) located below the link give you counts for policy violations and are based on the associated severities (critical, severe, and moderate).
In addition to the summary, a historical graph is shown to indicate policy health over time.
The Application Report is accessible from the summary by clicking "view report" or "Lifecycle Policy Evaluation" in the left-hand navigation. Additionally, a Build Report is available within Jenkins by clicking the "IQ Build Report" in the left-hand nav. This build report shows which components caused a 'warn' or 'fail' action on a particular build.
If you are looking for previous report results, navigate to a specific build report in the Build History. Click on the link View Report to view the build report in IQ Server.
Advanced Step Options
There are various advanced options that allow you to configure your policy evaluation.
Scan Targets: By default, the plugin scans all files in the workspace. Any special non-archive files like manifests may incur special handling depending on the version of the plugin used. Each Scan Target field takes an Apache Ant-styled pattern (i.e. **/*.js). Supplying custom scan targets will limit scanning to only those files matching the scan targets. Only one scan target can be placed on each line.
Modules in workspace: The Sonatype CLM for Maven has an index goal that can be used to create a module.xml file with all an application's components. By default, any module.xml file within its default directory will be scanned and evaluated for policy evaluation.
The default directories that the Jenkins plugin scans for module.xml files are **/sonatype-clm and **/nexus-iq . Any module.xml file located elsewhere in the scan targets will be ignored.
If using the Sonatype CLM for Maven plugin to index, the Maven path settings in Jenkins must be locally accessible by the IQ Plugin.The IQ plugin relies on the Maven settings defined globally in the Jenkins UI to access the files from the Maven build output to perform evaluation.
Module excludes:
The Module Excludes feature can be used to exclude any of these module.xml files from evaluation. Module Excludes takes Apache Ant-styled patterns (i.e. **/sonatype-clm/module.xml).
Module Excludes is only for excluding module.xml files generated by Sonatype CLM for Maven and is not an option for excluding scan targets.
Fail build when unable to communicate with IQ Server: Enabling this option will fail the build when the IQ Server is unreachable.
Fail build when there are scanning errors: Enabling this option will fail the build when there are scanning errors, e.g. malformed files that could not be read.
Use job-specific credentials: This allows overriding the global credential configuration with job-specific authentication credentials.
Advanced properties: A number of additional parameters can be supplied to the plugin using this input field. Typically these parameters will be determined by Sonatype support.
Enable debug logging: Increase the verbosity of the plugin-specific job logging to aid in diagnosing scanning problems or verifying scanning configuration.
Evaluating Docker Images
Use the container:
prefix in the scanPattern
to scan the docker images you want to scan.
nexusPolicyEvaluation iqApplication: 'appId', iqInstanceId: 'MyIQServer1', iqScanPatterns: [[scanPattern: 'container:namespace/image:image-tag']], iqStage: 'build'