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
Copy file name to clipboardExpand all lines: docs/codeql/codeql-cli/creating-codeql-databases.rst
+117
Original file line number
Diff line number
Diff line change
@@ -228,6 +228,123 @@ commands that you can specify for compiled languages.
228
228
This command runs a custom script that contains all of the commands required
229
229
to build the project.
230
230
231
+
Using indirect build tracing
232
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
233
+
234
+
If the CodeQL CLI autobuilders for compiled languages do not work with your CI workflow and you cannot wrap invocations of build commands with ``codeql database trace-command``, you can use indirect build tracing to create a CodeQL database. To use indirect build tracing, your CI system must be able to set custom environment variables for each build action.
235
+
236
+
To create a CodeQL database with indirect build tracing, run the following command from the checkout root of your project:
- ``<database>``: a path to the new database to be created. This directory will
245
+
be created when you execute the command---you cannot specify an existing
246
+
directory.
247
+
- ``--begin-tracing``: creates scripts that can be used to set up an environment in which build commands will be traced.
248
+
249
+
You may specify other options for the ``codeql database init`` command as normal.
250
+
251
+
.. pull-quote:: Note
252
+
253
+
If the build runs on Windows, you must set either ``--trace-process-level <number>`` or ``--trace-process-name <parent process name>`` so that the option points to a parent CI process that will observe all build steps for the code being analyzed.
254
+
255
+
256
+
The ``codeql database init`` command will output a message::
257
+
258
+
Created skeleton <database>. This in-progress database is ready to be populated by an extractor.
259
+
In order to initialise tracing, some environment variables need to be set in the shell your build will run in.
260
+
A number of scripts to do this have been created in <database>/temp/tracingEnvironment.
261
+
Please run one of these scripts before invoking your build command.
262
+
263
+
Based on your operating system, we recommend you run: ...
264
+
265
+
The ``codeql database init`` command creates ``<database>/temp/tracingEnvironment`` with files that contain environment variables and values that will enable CodeQL to trace a sequence of build steps. These files are named ``start-tracing.{json,sh,bat,ps1}``. Use one of these files with your CI system's mechanism for setting environment variables for future steps. You can:
266
+
267
+
* Read the JSON file, process it, and print out environment variables in the format expected by your CI system. For example, Azure DevOps expects ``echo "##vso[task.setvariable variable=NAME]VALUE"``.
268
+
* Or, if your CI system persists the environment, source the appropriate ``start-tracing`` script to set the CodeQL variables in the shell environment of the CI system.
269
+
270
+
Build your code; optionally, unset the environment variables using an ``end-tracing.{json,sh,bat,ps1}`` script from the directory where the ``start-tracing`` scripts are stored; and then run the command ``codeql database finalize <database>``.
271
+
272
+
Once you have created a CodeQL database using indirect build tracing, you can work with it like any other CodeQL database. For example, analyze the database, and upload the results to GitHub if you use code scanning.
273
+
274
+
Example of creating a CodeQL database using indirect build tracing
0 commit comments