Publishing and using CodeQL packs

Share or download a CodeQL pack, then analyze your CodeQL database.

Authenticating to GitHub Container registries

You can publish packs and download private packs by authenticating to the appropriate GitHub Container registry.

You can authenticate to the Container registry in two ways:

  1. Pass the --github-auth-stdin option to the CodeQL CLI, then supply a GitHub Apps token or personal access token via standard input.
  2. Set the GITHUB_TOKEN environment variable to a GitHub Apps token or personal access token.

Publishing your CodeQL pack

To share your CodeQL pack with other people, you can publish it to the Container registry.

Configuring the qlpack.yml file before publishing

You can check and modify the configuration details of your CodeQL pack prior to publishing. Open the qlpack.yml file in your preferred text editor.

library: # set to true if the pack is a library. Set to false or omit for a query pack
name: <scope>/<pack>
version: <x.x.x>
description: <Description to publish with the package>
defaultSuite: # optional, one or more queries in the pack to run by default
    - query: <relative-path>/query-file>.ql
defaultSuiteFile: default-queries.qls # optional, a pointer to a query-suite in this pack
license: # optional, the license under which the pack is published
dependencies: # map from CodeQL pack name to version range

Running codeql pack publish

When you are ready to publish a pack to the GitHub Container registry, you can run the following command in the root of the pack directory:

codeql pack publish

The published package will be displayed in the packages section of GitHub organization specified by the scope in the qlpack.yml file.

Note

If you're publishing model packs to the GitHub Container registry in order to extend coverage to all repositories in an organization as part of a default setup configuration, then you need to ensure that repositories running code scanning can access those model packs. For more information, see Editing your configuration of default setup and Configuring a package's access control and visibility.

Downloading an existing CodeQL pack

To run a pack that someone else has created, you must first download it by running the following command:

codeql pack download <scope>/<pack>@x.x.x

This command accepts arguments for multiple packs.

If you write scripts that specify a particular version number of a
query pack to download, keep in mind that when you update your version of
CodeQL to a newer one, you may
also need to switch to a newer version of the query pack. Newer
versions of CodeQL may provide
degraded performance when used with query packs that have been pinned
to a very old version. For more information, see CodeQL query packs reference.

Using a CodeQL pack to analyze a CodeQL database

To analyze a CodeQL database with a CodeQL pack, run the following command:

codeql database analyze <database> <scope>/<pack>@x.x.x:<path>

The analyze command will run the default suite of any specified CodeQL packs. You can specify multiple CodeQL packs to be used for analyzing a CodeQL database. For example:

codeql <database> analyze <scope>/<pack> <scope>/<other-pack>

Note

The codeql pack download command stores the pack it downloads in an internal location that is not intended for local modification. Unexpected (and hard to troubleshoot) behavior may result if the pack is modified after downloading. For more information about customizing packs, see Creating and working with CodeQL packs.