Sample PR integrations in CI

We have captured here typical use cases of Pull Request Integration.

Maven Build for a Java application

In the example below, we simply create the buildSessionId outside the JSON command using the relevant parameters.

In the sample script below, please update lines 7 and 8 before executing it.

#!/bin/bash
echo "Downloading Sealights Agents..."
wget -nv https://agents.sealights.co/sealights-java/sealights-java-latest.zip
unzip -o sealights-java-latest.zip

# sample values
export SL_APP_NAME="myApp"
export SL_PACKAGES_INCLUDED="*com.mycompany.*"

# Pull request parameters per the Sealights documentation
if [ -n "${BITBUCKET_PR_ID}" ]; then
      #Pull Request context (Bitbucket environment variables)
      java -jar sl-build-scanner.jar -prConfig -token $SL_TOKEN -appname $SL_APP_NAME \
            -targetBranch "origin/$BITBUCKET_PR_DESTINATION_BRANCH" -pullRequestNumber $BITBUCKET_PR_ID \
            -latestCommit $BITBUCKET_COMMIT -repoUrl "https://bitbucket.mycompany.int/$BITBUCKET_REPO_SLUG" \
            -pi $SL_PACKAGES_INCLUDED
else
      #Regular Build
      java -jar sl-build-scanner.jar -config -token $SL_TOKEN -appname $SL_APP_NAME \
            -branchname "${GIT_BRANCH}" -buildname "${BUILD_NUMBER}" -pi $SL_PACKAGES_INCLUDED
fi

echo  '{
        "token": ${SL_TOKEN},
        "createBuildSessionId": false,
        "buildSessionIdFile": "./buildSessionId.txt",
        "filesIncluded": "*.class",
        "filesExcluded": "*test-classes*",
        "recursive": true,
        "includeResources": true,
        "testStage": "Unit Tests",
        "labId": null,
        "executionType": "full",
        "logEnabled": false,
        "logDestination": "console",
        "logLevel": "off",
        "logFolder": "/tmp/sl-logs",
        "sealightsJvmParams": {},
        "enabled": true,
        "filesStorage": "/tmp"
}' > slmaven.json
  
echo "Updating POM with Sealights..."
java -jar sl-build-scanner.jar -pom -configfile slmaven.json -workspacepath .

Azure DevOps Pipeline for a DotNet application

In the sample script below, if required, please update lines 1 to 4 and 25-26 before executing it.

Lines 8-9, 22-23 and 26-27 contain the ` characters allowing multi-line commands in Powershell scripts, to increase readiness of this sample code.

Last updated

Was this helpful?