Table of Contents | ||
---|---|---|
|
SeaLights build scanner (sl-build-scanner.jar
) can be used to update build.gradle
script with the changes needed to run your Gradle build using SeaLights Gradle plugin in a similar fashion , similarly as for Maven pom integration.
Note |
---|
Automatic integration of Sealights settings into your build.gradle script is currently supported only for Groovy language. |
Configuration file
Create a JSON configuration file with the following parameters in order to provide the necessary configuration fields to the SeaLights Gradle plugin:
token or tokenFile - set with a token or a file containing the token obtained from the SeaLights dashboard
Managing the session ID
If you create a Build Session ID externally, provide the following fields:
buildSessionId or buildSessionIdFile - Set with a build session id or a file containing the build session id created by the config step
createBuildSessionId - Set to false
If you want to create a Build Session ID using the SeaLights Gradle plugin, provide the following fields:
createBuildSessionId - Set to true
appName - Name of the application as you want to see it on the SeaLights dashboard
branchName - Name of the branch as you want to see it on the SeaLights dashboard
buildName - Name of the build as you want to see it on the SeaLights dashboard
packagesIncluded - Comma-separated list of packages to include in the scan operation. Note: This is defining a subset, so it must include the
...
star to include all sub-packages/classes
...
executionType - Provide which executions need to handled by the Gradle plugin
full - Execute both the build scanner and the test listener
testsonly - Execute only the test listener
...
filesincluded - (Optional) Set to the binary files to scan. Default: *.class
...
filesexcluded - (Optional) Set to the binary files to excluded from the scan. Default: *test-classes*
...
workspacepath - Set to the path to the binary files to scan. Default: project.buildDir
...
recursive - (Optional) Set to true to scan all the subdirectories of workspacepath. Default: true
If you want to create a Pull Request Build Session ID using the SeaLights Maven plugin, provide the following fields:
createPRBuildSessionId - Set to true
appName - Name of the application as you want to see it on the SeaLights dashboard
targetBranch - The branch to which this PR will be merged (already reported to SeaLights)
pullRequestNumber - The number assigned to the Pull Request from the source control
latestCommit - The full SHA of the last commit made to the Pull Request
repositoryUrl - The pull request URL for the PR to be scanned up until the section before the
pullRequestNumber
valuepackagesIncluded - Comma-separated list of packages to include in the scan. Note: This is defining a subset, so it must include the asterisk to include all sub-packages/classes
packagesExcluded - (Optional) Comma-separated list of packages to include in the scan. Note: This is defining a subset, so it must include the asterisk to include all sub-packages/classes
executionType - Provide which executions need to be handled by the Gradle plugin
full - Execute both the build scanner and the test listener
scanonly - Execute only the build scanner
testTasksAndStages - (Optional) Mapping of test
...
tasks’ names to test stage names as they will be displayed on the SeaLights dashboard. It should be of the format {"testTask1":"testStage1", "testTask2":"testStage2"}
...
...
filesStorage - Set to the temp folder for the agent to create temporary files in. For example /tmp
...
logEnabled - Set to true if you want a log to be created
...
logLevel - Set the log level to create. For example WARN or INFO
proxy - (Optional) Address of proxy to run connection through
...
sealightsJvmParams - Entry to provide JVM params to the SeaLights agent. It should be of the format {"key1":"val1", "key2":"val2"}
The values provided for fields can contain interpolated Groovy code, just like for the field appName
in the above example: "${System.getenv('JOB_NAME')}"
.
It will get resolved during the Gradle build.
Note |
---|
|
Info |
---|
Info |
For additional parameters values and information, see 'Java Command Reference - Installing test listener as Java Agent' for more parameter values and information |
Code Block | ||
---|---|---|
| ||
{ "executionType": "scanonly", "tokenFile": "./sltoken.txt", "createBuildSessionId": true, "appName": "${System.getenv('JOB_NAME')}", "branchName": "master", "buildName": "${System.getenv('BUILD_NUMBER')}", "packagesIncluded": "*com.example.*", "packagesExcluded": "", "filesIncluded": "*.class", "filesExcluded": "*test-classes*", "recursive": true, "includeResources": true, "testTasksAndStages": {"test":"Unit Tests", "junitPlatformTest":"Unit Tests", "integrationTest":"Integration Tests"}, "labId": null, "executionType": "full", "logEnabled": false, "logDestination": "console", "logLevel": "off", "logFolder": "/tmp", "gradleProjectConfig": { "excludedProjects": ["subProject1", "subProject2"], "repoConfig": "mavenLocal()" } } |
The values provided for fields can contain interpolated Groovy code, just like for the field appName
in the above example: "${System.getenv('JOB_NAME')}"
.
It will get resolved during the Gradle build.
Note |
---|
|
Integrating into the Build.gradle script
Before running your Gradle build, you run the build scanner with -gradle
flag to integrate the SeaLights Gradle plugin into the build.gradle
file. This will create a sealights.gradle
script with all the configuration taken from the JSON config file and append a reference to it in build.gradle
.
The standard parameters the build scanner receives are:
configfile - The path to the JSON configuration you created with the parameters to be provided to the SeaLights Gradle plugin
workspacepath - The base path to the location of the
build.gradle
file to update
Code Block | ||
---|---|---|
| ||
java -jar sl-build-scanner.jar -gradle -configfile sl-config.json -workspacepath . |
...
Note |
---|
This step will update the root |
Next The next step is to run your regular Gradle build command, e.g. ‘gradle clean buildbuild’.
Restoring the build.gradle file to its previous state
In case If the project is to be restored to its previous state before the SeaLights plugin was applied, use the build scanner with the -restoreGradle
flag on the workspace where the gradle.build
file is located:
...
This command will (1) restore gradle.build
from its backup, (2) delete the backup file, and (3) delete the sealights.gradle
file.
Failure at any of these steps won’t prevent the next ones , so that the project is restored as much as possible.
Configuring
...
SCM to enable links from the dashboard
SeaLights, by default, provides all links to the SCM for Github. You can configure SeaLights to prepare the links for Bitbucket and Gitlab as well with the following parameters placed under the sealightsJvmParams
section:
sl.scm.provider - set to github, Bitbucket or gitlab
sl.scm.baseUrl - When working with an on-premise installation of your SCM and access from the build machine is different than the one accessed by the users, then you can provide the base URL to use
sl.scm.version - set to the version of the on-premise version you use
Code Block |
---|
"sealightsJvmParams": { "sl.scm.provider": "bitbucket", "sl.scm.baseUrl": "https://my.bitbucket.com/projects/ABCD/repos/XYZ/browse/A1", "sl.scm.version": "4.9.0" } |
Pre-downloading the agents
The Gradle plugin downloads the recommended agent at the beginning of the run. If you want to pre-download them and provide them to the plugin, you can do so with the flags scannerJar & listenerJarflags scannerJar
& listenerJar
.
The agents referred here can be either the latest agent or the recommended one set in your account settings as stated in Downloading the java agent files. They should be downloaded and made available prior to the Gradle execution.
Code Block |
---|
"scannerJar": "./sl-build-scanner.jar"
"listenerJar": "./sl-test-listener.jar" |
The agents used here should be downloaded either with the latest agent or the recommended one as stated in Downloading the java agent files |
...
Using a local repo
The Gradle plugin, by default, is downloaded from Maven Central. If you want to update the repo it downloads from, you can do so using the gradleProjectConfig->repoConfig option
As repo configurations are usually multiline, its important to maintain this new line format using \n
Code Block |
---|
"gradleProjectConfig": {"repoConfig": "maven{\nurl \"https://artifactory.company.com/artifactory/remote-repos\"\ncredentials {\nusername = \"USERNAME\"\npassword = \"PASSWORD\"\n}\n}"} |
Samples
Table of Contents | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Shell script
Info |
---|
This script is very often added to a new pre-build step in your CI configuration (i.e. Jenkins). |
Code Block | ||
---|---|---|
| ||
echo "Downloading Sealights Agents..." wget -nv https://agents.sealights.co/sealights-java/sealights-java-latest.zip unzip -o sealights-java-latest.zip echo "Sealights agent version used is:" `cat sealights-java-version.txt` echo '{ "executionType": "scanonly", "tokenFile": "sltoken.txt", "createBuildSessionId": true, "appName": "${System.getenv(\"JOB_NAME\")}", "branchName": "${System.getenv(\"GIT_BRANCH\")}", "buildName": "${System.getenv(\"BUILD_NUMBER\")}SL_Timestamp", "packagesIncluded": "*com.example.*", "packagesExcluded": "", "filesIncluded": "*.class", "filesExcluded": "*test-classes*", "recursive": true, "includeResources": true, "testTasksAndStagesproxy": null, {"testlogEnabled": "Unit Tests"}false, "logDestination": "console", "labIdlogLevel": null"off", "executionTypelogFolder": "full/tmp/sl-logs", "logEnabledscannerJar": false"./sl-build-scanner.jar", "logDestinationlistenerJar": "console./sl-test-listener.jar", "logLevelsealightsJvmParams": "off", { "logFoldersl.scm.provider": "/tmpbitbucket" } }' > sl-gradle-configbuild.json echo "Updating Build.gradle with Sealights..." java -jar sl-build-scanner.jar -gradle -configfile sl-gradle-configbuild.json -workspacepath . |
Next step is to run your regular Gradle build command, e.g. gradle clean build.
Gitlab YML
Info |
---|
In the example below:
|
Code Block | ||
---|---|---|
| ||
build:
stage: build
before_script:
- echo "Downloading Sealights Agents..."
- wget -nv https://agents.sealights.co/sealights-java/sealights-java-latest.zip
- unzip -o sealights-java-latest.zip
- echo "Sealights agent version used is:" `cat sealights-java-version.txt`
- >
echo '{
"executionType":"scanonly",
"token":"'$SEALIGHTS_AGENT_TOKEN'",
"createBuildSessionId":true,
"appName":"'$CI_PROJECT_NAME'",
"branchName":"'$CI_COMMIT_BRANCH'",
"buildName":"'$CI_PIPELINE_ID - $CI_JOB_STARTED_AT'",
"packagesIncluded":"*com.mycompany.*",
"sealightsJvmParams": {
"sl.scm.provider": "gitlab",
"sl.scm.baseUrl": "'${CI_SERVER_URL}/${CI_PROJECT_PATH}'/blob" }
}' > sl-plugin-settings.json
- cat sl-plugin-settings.json
- echo "Updating Gradle with Sealights..."
- java -jar sl-build-scanner.jar -gradle -configfile sl-plugin-settings.json -workspacepath . |
The rest of your pipeline is unchanged.
Page Properties | ||
---|---|---|
| ||
|