You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- ``--sarif-category``: an identifying category for the results. Used when
61
66
you want to upload more than one set of results for a commit.
62
67
For example, when you use ``github upload-results`` to send results for more than one
63
68
language to the GitHub code scanning API. For more information about this use case,
64
69
see `Configuring CodeQL CLI in your CI system <https://docs.github.com/en/code-security/secure-coding/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-cli-in-your-ci-system>`__ in the GitHub documentation.
65
70
66
-
- ``--sarif-add-query-help``: (supported in version 2.7.1 onwards) adds any custom query help written
67
-
in markdown to SARIF files (v2.1.0 or later) generated by the analysis. Query help stored in ``.qhelp`` files must be
68
-
converted to ``.md`` before running the analysis. For further information,
69
-
see ":ref:`Including query help for custom CodeQL queries in SARIF files <including-query-help-for-custom-codeql-queries-in-sarif-files>`."
71
+
- ``--sarif-add-query-help``: (supported in version 2.7.1 onwards) adds any custom query help written
72
+
in markdown to SARIF files (v2.1.0 or later) generated by the analysis. Query help stored in ``.qhelp`` files must be
73
+
converted to ``.md`` before running the analysis. For further information,
74
+
see ":ref:`Including query help for custom CodeQL queries in SARIF files <including-query-help-for-custom-codeql-queries-in-sarif-files>`."
75
+
76
+
- ``--download``: a boolean flag that will allow the CLI to download any referenced CodeQL packages that are not available locally.
77
+
If this flag is missing and a referenced CodeQL package is not available locally, the command will fail.
The ``analyze`` command above runs the default suite from ``microsoft/coding-standards v1.0.0`` and the latest version of ``scope/other-pack`` on the specified database.
135
+
The ``analyze`` command above runs the default suite from ``microsoft/coding-standards v1.0.0`` and the latest version of ``github/secutiry-queries`` on the specified database.
131
136
For further information about default suites, see ":ref:`Publishing and using CodeQL packs <publishing-and-using-codeql-packs>`".
132
137
138
+
For more information about CodeQL packs, see :doc:`About CodeQL Packs <about-codeql-packs>`.
139
+
133
140
Running query suites
134
141
~~~~~~~~~~~~~~~~~~~~
135
142
@@ -176,7 +183,7 @@ Integrating a CodeQL pack into a code scanning workflow in GitHub
You can use CodeQL query packs in your Code Scanning setup. This allows you to select query packs published by various sources and use them to analyze your code.
186
+
You can use CodeQL query packs in your code scanning setup. This allows you to select query packs published by various sources and use them to analyze your code.
180
187
For more information, see "`Using CodeQL query packs in the CodeQL action <https://docs.github.com/en/code-security/secure-coding/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-codeql-query-packs/>`_" or "`Downloading and using CodeQL query packs in your CI system <https://docs.github.com/en/code-security/secure-coding/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-cli-in-your-ci-system#downloading-and-using-codeql-query-packs>`_."
181
188
182
189
@@ -206,28 +213,28 @@ A SARIF results file is generated. Specifying ``--format=sarif-latest`` ensures
206
213
that the results are formatted according to the most recent SARIF specification
If you use the CodeQL CLI to to run code scanning analyses on third party CI/CD systems,
215
222
you can include the query help for your custom queries in SARIF files generated during an analysis.
216
-
After uploading the SARIF file to GitHub, the query help is shown in the code scanning UI for any
217
-
alerts generated by the custom queries.
223
+
After uploading the SARIF file to GitHub, the query help is shown in the code scanning UI for any
224
+
alerts generated by the custom queries.
218
225
219
-
From CodeQL CLI 2.7.1 onwards, you can include markdown-rendered query help in SARIF files
226
+
From CodeQL CLI 2.7.1 onwards, you can include markdown-rendered query help in SARIF files
220
227
by providing the ``--sarif-add-query-help`` option when running
221
-
``codeql database analyze``.
228
+
``codeql database analyze``.
222
229
For more information, see `Configuring CodeQL CLI in your CI system <https://docs.github.com/en/code-security/code-scanning/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-cli-in-your-ci-system#analyzing-a-codeql-database>`__
223
230
in the GitHub documentation.
224
231
225
232
You can write query help for custom queries directly in a markdown file and save it alongside the
226
-
corresponding query. Alternatively, for consistency with the standard CodeQL queries,
227
-
you can write query help in the ``.qhelp`` format. Query help written in ``.qhelp``
233
+
corresponding query. Alternatively, for consistency with the standard CodeQL queries,
234
+
you can write query help in the ``.qhelp`` format. Query help written in ``.qhelp``
228
235
files can't be included in SARIF files, and they can't be processed by code
229
-
scanning so must be converted to markdown before running
230
-
the analysis. For more information, see ":ref:`Query help files <query-help-files>`"
236
+
scanning so must be converted to markdown before running
237
+
the analysis. For more information, see ":ref:`Query help files <query-help-files>`"
231
238
and ":doc:`Testing query help files <testing-query-help-files>`."
Copy file name to clipboardExpand all lines: docs/codeql/codeql-cli/getting-started-with-the-codeql-cli.rst
+87-36Lines changed: 87 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,8 @@ to display in GitHub as code scanning alerts, see
30
30
`Installing CodeQL CLI in your CI system <https://docs.github.com/en/code-security/secure-coding/using-codeql-code-scanning-with-your-existing-ci-system/installing-codeql-cli-in-your-ci-system>`__
31
31
in the GitHub documentation.
32
32
33
+
.. _download-cli:
34
+
33
35
1. Download the CodeQL CLI zip package
34
36
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35
37
@@ -84,6 +86,90 @@ Alternatively, you can download ``codeql.zip``, which contains the CLI for all s
84
86
iv. Ensure the check-box labeled **Open "safe" files after downloading**.
85
87
is unchecked.
86
88
89
+
2. Extract the zip archive
90
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
91
+
92
+
For Linux, Windows, and macOS users (version 10.14 "Mojave", and earlier)
93
+
simply extract the zip archive.
94
+
95
+
.. container:: toggle
96
+
97
+
.. container:: name
98
+
99
+
**Information for macOS "Catalina" (or newer) users**
100
+
101
+
.. pull-quote:: macOS "Catalina"
102
+
103
+
macOS "Catalina", "Big Sur", or "Monterey" users should run the following
104
+
commands in the Terminal, where ``${extraction-root}`` is the path to the
105
+
directory where you will extract the CodeQL CLI zip archive:
106
+
107
+
i. ``mv ~/Downloads/codeql*.zip ${extraction-root}``
108
+
ii. ``cd ${extraction-root}``
109
+
iii. ``/usr/bin/xattr -c codeql*.zip``
110
+
iv. ``unzip codeql*.zip``
111
+
112
+
.. _launch-codeql-cli:
113
+
114
+
3. Launch ``codeql``
115
+
~~~~~~~~~~~~~~~~~~~~
116
+
117
+
Once extracted, you can run CodeQL processes by running the ``codeql``
118
+
executable in a couple of ways:
119
+
120
+
- By executing ``<extraction-root>/codeql/codeql``, where
121
+
``<extraction-root>`` is the folder where you extracted the CodeQL CLI
122
+
package.
123
+
- By adding ``<extraction-root>/codeql`` to your ``PATH``, so that you
124
+
can run the executable as just ``codeql``.
125
+
126
+
At this point, you can execute CodeQL commands. For a full list of the CodeQL
127
+
CLI commands, see the "`CodeQL CLI manual <../manual>`__."
128
+
129
+
.. pull-quote:: Note
130
+
131
+
If you add ``codeql`` to your ``PATH``, it can be accessed by CodeQL
132
+
for Visual Studio Code to compile and run queries.
133
+
For more information about configuring VS Code to access the CodeQL CLI, see
134
+
":ref:`Setting up CodeQL in Visual Studio Code <setting-up-codeql-in-visual-studio-code>`."
135
+
136
+
137
+
4. Verify your CodeQL CLI setup
138
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139
+
140
+
CodeQL CLI has subcommands you can execute to verify that you are correctly set
141
+
up to create and analyze databases:
142
+
143
+
- Run ``codeql resolve languages`` to show which languages are
144
+
available for database creation. This will list the languages supported by
145
+
default in your CodeQL CLI package.
146
+
- (Optional) You can download some ":ref:`CodeQL packs <about-codeql-packs>`" containing pre-compiled queries you would like to run.
147
+
To do this, run ``codeql pack download <pack-name> [...pack-name]``, where ``pack-name`` is the name of
148
+
the pack you want to download. The core query packs are a good place to start. They are:
149
+
150
+
- ``codeql/cpp-queries``
151
+
- ``codeql/csharp-queries``
152
+
- ``codeql/java-queries``
153
+
- ``codeql/javascript-queries``
154
+
- ``codeql/python-queries``
155
+
- ``codeql/ruby-queries``
156
+
157
+
Alternatively, you can download query packs during the analysis by using the ``--download`` flag of the ``codeql database analyze``
158
+
command.
159
+
160
+
161
+
Checking out the CodeQL source code directly
162
+
--------------------------------------------
163
+
164
+
Some users prefer working with CodeQL query sources directly in order to work on or contribute to the Open Source shared queries. In
165
+
order to do this, the following steps are recommended. Note that the following instructions are a slightly more complicated alternative
166
+
to working with CodeQL packages as explained above.
167
+
168
+
1. Download the CodeQL CLI zip
169
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
170
+
171
+
Follow :ref:`step 1 from the previous section<download-cli>`.
172
+
87
173
2. Create a new CodeQL directory
88
174
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89
175
@@ -164,45 +250,11 @@ For example, if the path to your copy of the CodeQL repository is
164
250
``$HOME/codeql-home/codeql-repo``, then extract the CLI into
165
251
``$HOME/codeql-home/``.
166
252
167
-
.. container:: toggle
168
-
169
-
.. container:: name
170
-
171
-
**Information for macOS "Catalina" (or newer) users**
172
-
173
-
.. pull-quote:: macOS "Catalina"
174
-
175
-
macOS "Catalina", "Big Sur", or "Monterey" users should run the following
176
-
commands in the Terminal, where ``${install_loc}`` is the path to the
177
-
directory you created in step 2:
178
-
179
-
i. ``mv ~/Downloads/codeql*.zip ${install_loc}``
180
-
ii. ``cd ${install_loc}``
181
-
iii. ``/usr/bin/xattr -c codeql*.zip``
182
-
iv. ``unzip codeql*.zip``
183
253
184
254
5. Launch ``codeql``
185
255
~~~~~~~~~~~~~~~~~~~~
186
256
187
-
Once extracted, you can run CodeQL processes by running the ``codeql``
188
-
executable in a couple of ways:
189
-
190
-
- By executing ``<extraction-root>/codeql/codeql``, where
191
-
``<extraction-root>`` is the folder where you extracted the CodeQL CLI
192
-
package.
193
-
- By adding ``<extraction-root>/codeql`` to your ``PATH``, so that you
194
-
can run the executable as just ``codeql``.
195
-
196
-
At this point, you can execute CodeQL commands. For a full list of the CodeQL
197
-
CLI commands, see the "`CodeQL CLI manual <../manual>`__."
198
-
199
-
.. pull-quote:: Note
200
-
201
-
If you add ``codeql`` to your ``PATH``, it can be accessed by CodeQL
202
-
for Visual Studio Code to compile and run queries.
203
-
For more information about configuring VS Code to access the CodeQL CLI, see
204
-
":ref:`Setting up CodeQL in Visual Studio Code <setting-up-codeql-in-visual-studio-code>`."
205
-
257
+
See :ref:`step 3 from the previous section<launch-codeql-cli>`.
206
258
207
259
6. Verify your CodeQL CLI setup
208
260
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -227,7 +279,6 @@ up to create and analyze databases:
227
279
- Legacy packs that ensure custom queries and libraries created using older products are
0 commit comments