Skip to main content

Setting up code scanning for a repository

You can set up escaneo de código by adding a workflow to your repository.

If you have write permissions to a repository, you can set up or configure escaneo de código for that repository.

El Escaneo de código se encuentra disponible para repositorios que pertenecen a organizaciones de GitHub Enterprise Server. Esta característica requiere una licencia para la GitHub Advanced Security. Para obtener más información, consulta "Productos de GitHub".

Nota: Tu administrador de sitio debe habilitar el escaneo de código para tu instancia de GitHub Enterprise Server antes de que puedas utilizar esta característica. Si quieres utilizar GitHub Actions para escanear tu código, el administrador de sitio también puede habilitar las GitHub Actions y configurar la infraestructura que se requiera. Para obtener más información, consulta "Configurar el escaneo de código en tu aplicativo."

Options for setting up escaneo de código

You decide how to generate escaneo de código alerts, and which tools to use, at a repository level. GitHub Enterprise Server provides fully integrated support for CodeQL analysis, and also supports analysis using third-party tools. For more information, see "About escaneo de código."

Type of analysisOptions for generating alerts
CodeQLUsing GitHub Actions (see "Setting up escaneo de código using actions") or running CodeQL analysis in a third-party continuous integration (CI) system (see "About CodeQL escaneo de código in your CI system").
Third‑partyUsing GitHub Actions (see "Setting up escaneo de código using actions") or generated externally and uploaded to GitHub Enterprise Server (see "Uploading a SARIF file to GitHub").

Si ejecutas el escaneo de código utilizando configuraciones múltiples, entonces algunas veces una alerta tendrá varios orígenes de análisis. Si una alerta tiene varios orígenes de análisis, puedes ver el estado de la alerta para cada uno de ellos en la página de alertas. Para obtener más información, consulta la sección "Acerca de los orígenes de análisis".

Note: If you want to use the CodeQL analysis, note that this article describes the features available with the version of the CodeQL action and associated CodeQL CLI bundle included in the initial release of this version of GitHub Enterprise Server. If your enterprise uses a more recent version of the CodeQL action, see the Nube de GitHub Enterprise article for information on the latest features. For information on using the latest version, see "Configuring code scanning for your appliance."

Setting up escaneo de código manually

  1. En tu instancia de GitHub Enterprise Server, visita la página principal del repositorio.

  2. Debajo de tu nombre de repositorio, da clic en Seguridad. Pestaña de seguridad

  3. To the right of "Escaneo de código alerts", click Set up escaneo de código. If escaneo de código is missing, you need to ask an organization owner or repository administrator to enable GitHub Advanced Security. For more information, see "Managing security and analysis settings for your organization" or "Managing security and analysis settings for your repository." "Set up escaneo de código" button to the right of "Escaneo de código" in the Security Overview

  4. Under "Get started with escaneo de código", click Set up this workflow on the Flujo de trabajo de análisis de CodeQL or on a third-party workflow. "Set up this workflow" button under "Get started with escaneo de código" headingWorkflows are only displayed if they are relevant for the programming languages detected in the repository. The Flujo de trabajo de análisis de CodeQL is always displayed, but the "Set up this workflow" button is only enabled if CodeQL analysis supports the languages present in the repository.

  5. To customize how escaneo de código scans your code, edit the workflow.

    Generally you can commit the Flujo de trabajo de análisis de CodeQL without making any changes to it. However, many of the third-party workflows require additional configuration, so read the comments in the workflow before committing.

    For more information, see "Configuring escaneo de código."

  6. Use the Start commit drop-down, and type a commit message. Start commit

  7. Choose whether you'd like to commit directly to the default branch, or create a new branch and start a pull request. Choose where to commit

  8. Click Commit new file or Propose new file.

In the default Flujo de trabajo de análisis de CodeQL, escaneo de código is configured to analyze your code each time you either push a change to the default branch or any protected branches, or raise a pull request against the default branch. As a result, escaneo de código will now commence.

The on:pull_request and on:push triggers for code scanning are each useful for different purposes. For more information, see "Scanning pull requests" and "Scanning on push."

Bulk set up of escaneo de código

You can set up escaneo de código in many repositories at once using a script. If you'd like to use a script to raise pull requests that add a GitHub Actions workflow to multiple repositories, see the jhutchings1/Create-ActionsPRs repository for an example using PowerShell, or nickliffen/ghas-enablement for teams who do not have PowerShell and instead would like to use NodeJS.

Viewing the logging output from escaneo de código

After setting up escaneo de código for your repository, you can watch the output of the actions as they run.

  1. Debajo de tu nombre de repositorio, haz clic en Acciones. Pestaña de acciones en la navegación del repositorio principal

    You'll see a list that includes an entry for running the escaneo de código workflow. The text of the entry is the title you gave your commit message.

    Actions list showing escaneo de código workflow

  2. Click the entry for the escaneo de código workflow.

  3. Click the job name on the left. For example, Analyze (LANGUAGE).

    Log output from the escaneo de código workflow

  4. Review the logging output from the actions in this workflow as they run.

  5. Once all jobs are complete, you can view the details of any escaneo de código alerts that were identified. For more information, see "Managing escaneo de código alerts for your repository."

Note: If you raised a pull request to add the escaneo de código workflow to the repository, alerts from that pull request aren't displayed directly on the Escaneo de código page until the pull request is merged. If any alerts were found you can view these, before the pull request is merged, by clicking the n alerts found link in the banner on the Escaneo de código page.

Click the "n alerts found" link

Understanding the pull request checks

Each escaneo de código workflow you set to run on pull requests always has at least two entries listed in the checks section of a pull request. There is one entry for each of the analysis jobs in the workflow, and a final one for the results of the analysis.

The names of the escaneo de código analysis checks take the form: "TOOL NAME / JOB NAME (TRIGGER)." For example, for CodeQL, analysis of C++ code has the entry "CodeQL / Analyze (cpp) (pull_request)." You can click Details on a escaneo de código analysis entry to see logging data. This allows you to debug a problem if the analysis job failed. For example, for escaneo de código analysis of compiled languages, this can happen if the action can't build the code.

escaneo de código pull request checks

When the escaneo de código jobs complete, GitHub works out whether any alerts were added by the pull request and adds the "Escaneo de código results / TOOL NAME" entry to the list of checks. After escaneo de código has been performed at least once, you can click Details to view the results of the analysis. If you used a pull request to add escaneo de código to the repository, you will initially see an "Analysis not found" message when you click Details on the "Escaneo de código results / TOOL NAME" check.

Analysis not found for commit message

The table lists one or more categories. Each category relates to specific analyses, for the same tool and commit, performed on a different language or a different part of the code. For each category, the table shows the two analyses that escaneo de código attempted to compare to determine which alerts were introduced or fixed in the pull request.

For example, in the screenshot above, escaneo de código found an analysis for the merge commit of the pull request, but no analysis for the head of the main branch.

Reasons for the "Analysis not found" message

After escaneo de código has analyzed the code in a pull request, it needs to compare the analysis of the topic branch (the branch you used to create the pull request) with the analysis of the base branch (the branch into which you want to merge the pull request). This allows escaneo de código to compute which alerts are newly introduced by the pull request, which alerts were already present in the base branch, and whether any existing alerts are fixed by the changes in the pull request. Initially, if you use a pull request to add escaneo de código to a repository, the base branch has not yet been analyzed, so it's not possible to compute these details. In this case, when you click through from the results check on the pull request you will see the "Analysis not found" message.

There are other situations where there may be no analysis for the latest commit to the base branch for a pull request. These include:

  • The pull request has been raised against a branch other than the default branch, and this branch hasn't been analyzed.

    To check whether a branch has been scanned, go to the Escaneo de código page, click the Branch drop-down and select the relevant branch.

Choose a branch from the Branch drop-down menu

The solution in this situation is to add the name of the base branch to the on:push and on:pull_request specification in the escaneo de código workflow on that branch and then make a change that updates the open pull request that you want to scan.

  • The latest commit on the base branch for the pull request is currently being analyzed and analysis is not yet available.

    Wait a few minutes and then push a change to the pull request to retrigger escaneo de código.

  • An error occurred while analyzing the latest commit on the base branch and analysis for that commit isn't available.

    Merge a trivial change into the base branch to trigger escaneo de código on this latest commit, then push a change to the pull request to retrigger escaneo de código.

Next steps

After setting up escaneo de código, and allowing its actions to complete, you can: