22
33Use this guide for pipeline-focused CLI usage across platforms.
44
5+ The shell commands in the recommended patterns are CI-provider neutral. Buildkite
6+ pipeline equivalents and provider-specific considerations are called out alongside
7+ the relevant guidance below.
8+
59## Recommended patterns
610
711### Dashboard-style reachable SARIF
@@ -27,6 +31,27 @@ socketcli \
2731 --strict-blocking
2832```
2933
34+ ### Buildkite: retain SARIF as a build artifact
35+
36+ Either recommended pattern can run directly in a Buildkite command step. When the
37+ scan writes SARIF, add
38+ [ ` artifact_paths ` ] ( https://buildkite.com/docs/pipelines/configure/artifacts#upload-artifacts-with-a-command-step )
39+ so developers can download the report from the build after the command finishes:
40+
41+ ``` yaml
42+ steps :
43+ - label : " :socket: Socket reachable diff"
44+ command : |
45+ socketcli \
46+ --reach \
47+ --sarif-file results.sarif \
48+ --sarif-scope diff \
49+ --sarif-reachability reachable \
50+ --strict-blocking
51+ artifact_paths :
52+ - " results.sarif"
53+ ` ` `
54+
3055## Config file usage in CI
3156
3257Use ` --config .socketcli.toml` or `--config .socketcli.json` to keep pipeline commands small.
@@ -60,6 +85,9 @@ Equivalent JSON:
6085}
6186` ` `
6287
88+ The Buildkite examples below use the same checked-in `.socketcli.toml` file; no
89+ Buildkite-specific config-file format is required.
90+
6391# # Platform examples
6492
6593# ## GitHub Actions
@@ -306,14 +334,33 @@ initial timeout signal or 137 if `SIGKILL` is involved.
306334
307335# ## Buildkite
308336
337+ This example assumes a GitHub-hosted repository. Change
338+ ` SOCKET_SCM_INTEGRATION` to `gitlab` for a GitLab-hosted repository, or `api`
339+ when provider association is not wanted. The doubled dollar signs defer
340+ Buildkite variable expansion until the command runs on an agent.
341+
309342` ` ` yaml
343+ env:
344+ SOCKET_SCM_INTEGRATION: "github"
345+
310346steps:
311347 - label: "Socket scan"
312- command: "socketcli --config .socketcli.toml --target-path ."
313- env:
314- SOCKET_SECURITY_API_TOKEN: "${SOCKET_SECURITY_API_TOKEN}"
348+ command: |
349+ socketcli \
350+ --config .socketcli.toml \
351+ --target-path . \
352+ --integration "$${SOCKET_SCM_INTEGRATION:-api}" \
353+ --pr-number "$${BUILDKITE_PULL_REQUEST:-0}"
354+ secrets:
355+ - SOCKET_SECURITY_API_TOKEN
315356` ` `
316357
358+ The `secrets` block expects a
359+ [Buildkite secret](https://buildkite.com/docs/pipelines/security/secrets/buildkite-secrets)
360+ named `SOCKET_SECURITY_API_TOKEN`. If your organization uses an external secrets
361+ plugin or an agent hook instead, remove that block and inject the same environment
362+ variable through your existing mechanism. Do not store the token in pipeline YAML.
363+
317364The CLI reads Buildkite's native `BUILDKITE_COMMIT`, `BUILDKITE_BRANCH`,
318365` BUILDKITE_PULL_REQUEST` , and `BUILDKITE_PULL_REQUEST_BASE_BRANCH` variables.
319366For pull-request builds, ensure the checkout contains the base branch and the
@@ -385,6 +432,18 @@ socket_scan:
385432 SOCKET_SECURITY_API_TOKEN: $SOCKET_SECURITY_API_TOKEN
386433` ` `
387434
435+ # ## Azure Pipelines
436+
437+ ` ` ` yaml
438+ - script: |
439+ socketcli \
440+ --integration azure \
441+ --enable-diff \
442+ --target-path "$(Build.SourcesDirectory)"
443+ env:
444+ SOCKET_SECURITY_API_TOKEN: $(SOCKET_SECURITY_API_TOKEN)
445+ ` ` `
446+
388447# ## Bitbucket Pipelines
389448
390449` ` ` yaml
@@ -395,6 +454,44 @@ pipelines:
395454 - socketcli --config .socketcli.toml --target-path .
396455` ` `
397456
457+ # # Pull request and Dashboard association
458+
459+ The CLI sends the resolved pull request number with each full scan and attaches
460+ the pull request URL to diff scans so the Socket Dashboard can associate the
461+ report with its originating change. If `--pr-number` is supplied, it wins;
462+ passing `--pr-number 0` explicitly disables automatic association.
463+
464+ Without an explicit value, the CLI recognizes :
465+
466+ - GitHub Actions : ` PR_NUMBER` , then the PR number in `GITHUB_REF`.
467+ - GitLab CI : ` CI_MERGE_REQUEST_IID` .
468+ - Azure Pipelines : ` SYSTEM_PULLREQUEST_PULLREQUESTNUMBER` for GitHub-hosted
469+ repositories, otherwise `SYSTEM_PULLREQUEST_PULLREQUESTID` for Azure Repos.
470+
471+ # ## Buildkite PR context
472+
473+ Buildkite is SCM-provider neutral, so the CLI does not infer a provider or consume
474+ its PR variable automatically. Pass Buildkite's
475+ [`BUILDKITE_PULL_REQUEST`](https://buildkite.com/docs/pipelines/configure/environment-variables#BUILDKITE_PULL_REQUEST)
476+ value to
477+ ` --pr-number` and identify the repository host with `--integration`, as shown in
478+ the Buildkite platform example above. Buildkite sets `BUILDKITE_PULL_REQUEST` to
479+ ` false` outside PR builds; the CLI treats that value as no PR.
480+
481+ Use `--integration github` for GitHub-hosted repositories and `--integration gitlab`
482+ for GitLab-hosted ones. In both cases the CLI reads the repository slug and host from
483+ [`BUILDKITE_REPO`](https://buildkite.com/docs/pipelines/configure/environment-variables#BUILDKITE_REPO)
484+ to build the pull request or merge request link, so github.com, GitLab.com, and
485+ self-hosted installations all work without extra configuration. Setting
486+ ` CI_PROJECT_URL` still overrides the derived GitLab project URL. Keep `--scm api`
487+ unless you also intend to configure an existing GitHub or GitLab comment adapter and
488+ its provider token.
489+
490+ ` --scm github` and `--scm gitlab` also imply the matching scan integration for
491+ Dashboard metadata unless `--integration` was explicitly supplied. PR comments
492+ remain limited to the existing GitHub and GitLab SCM adapters; Azure receives
493+ console output and Dashboard association but does not post a PR comment.
494+
398495# # Workflow templates
399496
400497Prebuilt examples in this repo :
@@ -411,3 +508,11 @@ Prebuilt examples in this repo:
411508- ` --sarif-grouping alert` currently applies to `--sarif-scope full`.
412509- Diff-based SARIF can validly be empty when there are no matching net-new alerts.
413510- Keep API tokens in secret stores (`SOCKET_SECURITY_API_TOKEN`), not in config files.
511+ - In Buildkite pipeline YAML, follow its
512+ [runtime interpolation](https://buildkite.com/docs/pipelines/configure/environment-variables#runtime-variable-interpolation)
513+ guidance and use `$$` for variables that must expand when the command runs rather
514+ than when the pipeline is uploaded.
515+ - Security findings with `props.firstPatchedVersionIdentifier` show that value in
516+ the console table, including native Buildkite job logs, and in GitHub/GitLab
517+ security comments when that SCM adapter is configured. Findings without a known
518+ patched release leave the console cell blank and omit the comment field.
0 commit comments