Secure-coding lessons from Jenkins, CircleCI and other CI
If your pull requests are built outside GitHub Actions, you can still get lesson comments. Your CI uploads the scanner’s SARIF file to GitHub code scanning, and the RansomLeak GitHub App posts the comment from the alerts it sees.
The upload is done by the public image ghcr.io/ransomleak/secure-coding-cli:1 (release 1.1.0 or later). It talks only to GitHub, with your own token. Nothing is sent to RansomLeak from your CI, and you need no RansomLeak account or credential.
What works
Section titled “What works”| Repository hosted on | Built by Jenkins, CircleCI or another CI |
|---|---|
| github.com | Yes, with the GitHub App |
| GitHub Enterprise Server | No. The App works with github.com only |
| GitLab | No. Use the GitLab component in GitLab CI |
| Bitbucket Cloud | No. Use the Bitbucket pipe in Bitbucket Pipelines |
| Azure DevOps | No. Use the Azure DevOps task in Azure Pipelines |
The GitLab, Bitbucket and Azure DevOps integrations prove who they are with the signed identity token of the platform’s own pipeline. Jenkins has no such token, and we don’t accept unsigned claims about which repository a build came from.
Before you start
Section titled “Before you start”- Install the RansomLeak GitHub App on the repository.
- Make sure code scanning is available: public repositories, or private repositories with GitHub Code Security.
- Create a GitHub token that can upload code scanning results. A fine-grained token needs Code scanning alerts: Read and write on the repository. A classic token needs the
security_eventsscope. Store it as a secret in your CI.
Jenkins
Section titled “Jenkins”Use a multibranch pipeline with the GitHub Branch Source plugin, so pull request builds set CHANGE_ID. Add the token as a Secret text credential.
stage('RansomLeak lessons') { when { changeRequest() } environment { GITHUB_TOKEN = credentials('github-code-scanning-token') } steps { script { env.GITHUB_SHA = sh(returnStdout: true, script: 'git rev-parse HEAD^2 2>/dev/null || git rev-parse HEAD').trim() } sh ''' docker run --rm \ -e GITHUB_TOKEN -e GITHUB_SHA -e CHANGE_ID -e CHANGE_URL -e GIT_URL \ -v "$PWD:/work" -w /work \ ghcr.io/ransomleak/secure-coding-cli:1 \ ransomleak-secure-coding github-upload-sarif --sarif semgrep.sarif ''' }}By default Jenkins builds the pull request merged into its target branch. That merge commit exists only in Jenkins, so GitHub refuses it. The git rev-parse HEAD^2 line picks the pull request head instead. If you build the head revision directly, it simply returns HEAD.
CircleCI
Section titled “CircleCI”Save the token as GITHUB_TOKEN in a context or in the project’s environment variables. Turn on Only build pull requests so each pull request push has CIRCLE_PULL_REQUEST set.
ransomleak-lessons: docker: - image: ghcr.io/ransomleak/secure-coding-cli:1 steps: - attach_workspace: at: . - run: ransomleak-secure-coding github-upload-sarif --sarif semgrep.sarifCircleCI does issue OIDC tokens, but they name a CircleCI project, not a GitHub pull request. The GitHub App route needs no token from CircleCI at all, so the CLI doesn’t use it.
Other CI and self-hosted runners
Section titled “Other CI and self-hosted runners”Set four variables from your CI’s own ones and run the image:
| Variable | Value |
|---|---|
GITHUB_TOKEN |
The token from the steps above |
GITHUB_REPOSITORY |
owner/repo |
GITHUB_PR_NUMBER |
The pull request number. Leave it unset on branch builds |
GITHUB_SHA |
The full 40-character SHA of the pull request head commit |
docker run --rm \ -e GITHUB_TOKEN -e GITHUB_REPOSITORY -e GITHUB_PR_NUMBER -e GITHUB_SHA \ -v "$PWD:/work" -w /work \ ghcr.io/ransomleak/secure-coding-cli:1 \ ransomleak-secure-coding github-upload-sarif --sarif results.sarifHow it behaves
Section titled “How it behaves”- It uploads the SARIF file to the pull request’s
refs/pull/<number>/headref. Code scanning turns the results into alerts, and the App posts or updates one comment with up to five lessons. - It never fails your build. It always exits 0 and logs why it skipped, for example on a branch build, without a token, or when GitHub refuses the upload.
- It never logs the token, file paths or file contents.
- Files above 10 MB gzipped are skipped, which is GitHub’s limit.
- The results also appear in your repository’s code scanning tab, like any other SARIF upload.
Troubleshooting
Section titled “Troubleshooting”| What you see | Why |
|---|---|
GitHub returned HTTP 403 |
The token can’t upload code scanning results, or the private repository has no GitHub Code Security. |
GitHub returned HTTP 422 |
GITHUB_SHA isn’t the pull request head commit, or that commit was never pushed to GitHub. |
this is not a pull request build |
The build has no pull request number. This is expected on branch builds. |
| Upload works, but no comment | The App isn’t installed on the repository, or no finding has a CWE we have a lesson for. |