For the complete documentation index, see llms.txt. This page is also available as Markdown.

Generating a Session ID

Create a build session ID with slnodejs config (or prConfig for pull request builds) and pass it to the later commands of the same build.

A build session ID identifies one build of an application. Create it once per build, before the scan, and pass the same ID to every later command of that build (scan, runtime coverage, tests), so SeaLights links them as one cycle.

You need an agent token. See Generating an Agent token and Configuration → Token.

Create the build session ID

config creates the build session and writes its ID to the file buildSessionId in the working directory (or to the file you pass with --buildSessionIdFile).

printf '%s' "$SEALIGHTS_AGENT_TOKEN" > sltoken.txt
npx slnodejs config \
  --tokenFile sltoken.txt \
  --appName "my-app" \
  --branchName "main" \
  --buildName "$(date -u +%Y%m%d_%H%M%S)"
cat buildSessionId
Set-Content -Path sltoken.txt -Value $env:SEALIGHTS_AGENT_TOKEN -NoNewline
npx slnodejs config `
  --tokenFile sltoken.txt `
  --appName "my-app" `
  --branchName "main" `
  --buildName (Get-Date -Format "yyyyMMdd_HHmmss")
Get-Content buildSessionId
- name: Create SeaLights build session
  env:
    SEALIGHTS_AGENT_TOKEN: ${{ secrets.SEALIGHTS_AGENT_TOKEN }}
  run: |
    printf '%s' "$SEALIGHTS_AGENT_TOKEN" > sltoken.txt
    npx slnodejs config \
      --tokenFile sltoken.txt \
      --appName "${{ github.event.repository.name }}" \
      --branchName "${{ github.ref_name }}" \
      --buildName "${{ github.run_id }}-${{ github.run_attempt }}"

Naming rules

Flag
Rule

--appName

Stable for the application across builds and branches. Case-sensitive.

--branchName

The source branch. Case-sensitive.

--buildName

Unique for every build of the application and branch. Use the CI build number, the run ID plus attempt, or the commit SHA plus a timestamp. Locally, use a timestamp.

Optional: --beControlledVersions installs the slnodejs version that SeaLights recommends for your account before creating the session. See config in the Command Reference.

Use the build session ID in later commands

Pass the ID to every later command, in one of these ways:

Method
Example
When to use

File (default)

--buildSessionIdFile buildSessionId

Same job, or keep the file as a CI artifact for later jobs. scan, instrument, mocha, run, uploadReports and nycReport read buildSessionId in the working directory even without the flag.

Value

--buildSessionId "$SL_BSID"

Pass the ID between jobs or pipelines as a variable.

Environment variable

export SL_buildSessionId="$(cat buildSessionId)"

CLI commands read SL_buildSessionId (case-sensitive). The preload script also reads SL_BUILD_SESSION_ID.

Passing the ID to a later job:

For a later job, upload buildSessionId with actions/upload-artifact and download it in that job.

In a later job, map $[ dependencies.<job>.outputs['sealights.SL_BSID'] ] to a variable and pass it with --buildSessionId.

Pull request builds

In a pipeline that runs for a pull request, use prConfig instead of config. SeaLights then compares the pull request with its target branch. It writes the build session ID to the same file, so the rest of the pipeline does not change.

All four PR flags are required. See prConfig in the Command Reference.

Next step

Last updated

Was this helpful?