Running CodeQL queriesΒΆ
There are several options available for running one or more CodeQL queries on a codebase. The best option depends on what your aims are.
Work through a CodeQL tutorialΒΆ
If youβre working through a CodeQL tutorial, the CodeQL extension for Visual Studio Code allows you to run the queries in the tutorial. Unless you want to run the query on a specific code base, itβs easiest to run queries on one of the many CodeQL databases that are available on GitHub. To get started, see βInstalling CodeQL for Visual Studio Codeβ.
Develop a new CodeQL queryΒΆ
If youβre developing a new query, the CodeQL extension for Visual Studio Code allows you to run a query and compare the results with previous runs as you refine the query. The extension also provides autocomplete suggestions, syntax highlighting, and other features that make it easier to write and debug queries. To get started, see βInstalling CodeQL for Visual Studio Codeβ.
When youβre ready to test the query on a wide range of codebases, you can choose from the pre-defined sets of CodeQL databases or define a custom group of codebases to run the query against. For more information, see βRunning CodeQL queries at scale with multi-repository variant analysisβ.
Run your query against a specific codebaseΒΆ
If the codebase that you want to run your query against doesnβt have a CodeQL database, you can create one using the CodeQL CLI. For more information, see βSetting up the CodeQL CLIβ and βPreparing your code for CodeQL analysisβ.
Once you have created a CodeQL database, you can make the database available to the CodeQL extension in Visual Studio Code, or run the query using the CodeQL CLI. For more information, see βAnalyzing your code with CodeQL queriesβ.
Run the standard CodeQL queriesΒΆ
The easiest way to run the standard CodeQL queries on a repository hosted on the GitHub platform is to enable code scanning with CodeQL (this requires GitHub Actions to be enabled). When you enable default setup, you can choose from a default set of security queries or an extended set of security queries. Any results are shown as code scanning alerts on the Security tab of the repository. For more information, see βConfiguring default setup for code scanningβ.
If you want to run the standard CodeQL queries on a repository where GitHub Actions are disabled, you can use the CodeQL CLI in your existing CI system. For more information, see βUsing code scanning with your existing CI systemβ.