debian-mirror-gitlab/doc/ci/pipelines/settings.md
2023-04-23 21:23:45 +05:30

15 KiB

stage group info disqus_identifier type
Verify Pipeline Execution To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments https://docs.gitlab.com/ee/user/project/pipelines/settings.html reference, howto

Customize pipeline configuration (FREE)

You can customize how pipelines run for your project.

For an overview of pipelines, watch the video GitLab CI Pipeline, Artifacts, and Environments. Watch also GitLab CI pipeline tutorial for beginners.

Change which users can view your pipelines

For public and internal projects, you can change who can see your:

To change the visibility of your pipelines and related features:

  1. On the top bar, select Main menu > Projects and find your project.

  2. On the left sidebar, select Settings > CI/CD.

  3. Expand General pipelines.

  4. Select or clear the Public pipelines checkbox. When it is selected, pipelines and related features are visible:

    • For Public projects, to everyone.
    • For Internal projects, to all authenticated users except external users.
    • For Private projects, to all project members (Guest or higher).

    When it is cleared:

    • For Public projects, job logs, job artifacts, the pipeline security dashboard, and the CI/CD menu items are visible only to project members (Reporter or higher). Other users, including guest users, can only view the status of pipelines and jobs, and only when viewing merge requests or commits.
    • For Internal projects, pipelines are visible to all authenticated users except external users. Related features are visible only to project members (Reporter or higher).
    • For Private projects, pipelines and related features are visible to project members (Reporter or higher) only.

Change pipeline visibility for non-project members in public projects

You can control the visibility of pipelines for non-project members in public projects.

This setting has no effect when:

To change the pipeline visibility for non-project members:

  1. On the top bar, select Main menu > Projects and find your project.
  2. On the left sidebar, select Settings > General.
  3. Expand Visibility, project features, permissions.
  4. For CI/CD, choose:
    • Only project members: Only project members can view pipelines.
    • Everyone With Access: Non-project members can also view pipelines.
  5. Select Save changes.

The CI/CD permissions table lists the pipeline features non-project members can access when Everyone With Access is selected.

Auto-cancel redundant pipelines

You can set pending or running pipelines to cancel automatically when a new pipeline runs on the same branch. You can enable this in the project settings:

  1. On the top bar, select Main menu > Projects and find your project.
  2. On the left sidebar, select Settings > CI/CD.
  3. Expand General Pipelines.
  4. Select the Auto-cancel redundant pipelines checkbox.
  5. Select Save changes.

Use the interruptible keyword to indicate if a running job can be cancelled before it completes.

Prevent outdated deployment jobs

  • Introduced in GitLab 12.9.
  • In GitLab 15.5, the behavior was changed to prevent outdated job runs.

Your project may have multiple concurrent deployment jobs that are scheduled to run in the same time frame.

This can lead to a situation where an older deployment job runs after a newer one, which may not be what you want.

To avoid this scenario:

  1. On the top bar, select Main menu > Projects and find your project.
  2. On the left sidebar, select Settings > CI/CD.
  3. Expand General pipelines.
  4. Select the Prevent outdated deployment jobs checkbox.
  5. Select Save changes.

For more information, see Deployment safety.

Specify a custom CI/CD configuration file

Support for external .gitlab-ci.yml locations introduced in GitLab 12.6.

GitLab expects to find the CI/CD configuration file (.gitlab-ci.yml) in the project's root directory. However, you can specify an alternate filename path, including locations outside the project.

To customize the path:

  1. On the top bar, select Main menu > Projects and find your project.
  2. On the left sidebar, select Settings > CI/CD.
  3. Expand General pipelines.
  4. In the CI/CD configuration file field, enter the filename. If the file:
    • Is not in the root directory, include the path.
    • Is in a different project, include the group and project name.
    • Is on an external site, enter the full URL.
  5. Select Save changes.

NOTE: You cannot use your project's pipeline editor to edit CI/CD configuration files in other projects or on an external site.

Custom CI/CD configuration file examples

If the CI/CD configuration file is not in the root directory, the path must be relative to it. For example:

  • my/path/.gitlab-ci.yml
  • my/path/.my-custom-file.yml

If the CI/CD configuration file is on an external site, the URL must end with .yml:

  • http://example.com/generate/ci/config.yml

If the CI/CD configuration file is in a different project:

  • The file must exist on its default branch, or specify the branch as refname.
  • The path must be relative to the root directory in the other project.
  • The path must be followed by an @ symbol and the full group and project path.

For example:

  • .gitlab-ci.yml@namespace/another-project
  • my/path/.my-custom-file.yml@namespace/sub-group/another-project
  • my/path/.my-custom-file.yml@namespace/sub-group1/sub-group2/another-project:refname

If the configuration file is in a separate project, you can set more granular permissions. For example:

  • Create a public project to host the configuration file.
  • Give write permissions on the project only to users who are allowed to edit the file.

Then other users and projects can access the configuration file without being able to edit it.

Choose the default Git strategy

You can choose how your repository is fetched from GitLab when a job runs.

  1. On the top bar, select Main menu > Projects and find your project.
  2. On the left sidebar, select Settings > CI/CD.
  3. Expand General pipelines.
  4. Under Git strategy, select an option:
    • git clone is slower because it clones the repository from scratch for every job. However, the local working copy is always pristine.
    • git fetch is faster because it re-uses the local working copy (and falls back to clone if it doesn't exist). This is recommended, especially for large repositories.

The configured Git strategy can be overridden by the GIT_STRATEGY variable in the .gitlab-ci.yml file.

Limit the number of changes fetched during clone

You can limit the number of changes that GitLab CI/CD fetches when it clones a repository.

  1. On the top bar, select Main menu > Projects and find your project.
  2. On the left sidebar, select Settings > CI/CD.
  3. Expand General pipelines.
  4. Under Git strategy, under Git shallow clone, enter a value. The maximum value is 1000. To disable shallow clone and make GitLab CI/CD fetch all branches and tags each time, keep the value empty or set to 0.

In GitLab versions 14.7 and later, newly created projects have a default git depth value of 20. GitLab versions 14.6 and earlier have a default git depth value of 50.

This value can be overridden by the GIT_DEPTH variable in the .gitlab-ci.yml file.

Set a limit for how long jobs can run

You can define how long a job can run before it times out.

  1. On the top bar, select Main menu > Projects and find your project.
  2. On the left sidebar, select Settings > CI/CD.
  3. Expand General pipelines.
  4. In the Timeout field, enter the number of minutes, or a human-readable value like 2 hours. Must be 10 minutes or more, and less than one month. Default is 60 minutes.

Jobs that exceed the timeout are marked as failed.

You can override this value for individual runners.

Merge request test coverage results

If you use test coverage in your code, you can use a regular expression to find coverage results in the job log. You can then include these results in the merge request in GitLab.

If the pipeline succeeds, the coverage is shown in the merge request widget and in the jobs table. If multiple jobs in the pipeline have coverage reports, they are averaged.

MR widget coverage

Build status coverage

Add test coverage results using coverage keyword

To add test coverage results to a merge request using the project's .gitlab-ci.yml file, provide a regular expression using the coverage keyword.

Test coverage examples

Use this regex for commonly used test tools.

  • Simplecov (Ruby). Example: /\(\d+.\d+\%\) covered/.
  • pytest-cov (Python). Example: /(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/.
  • Scoverage (Scala). Example: /Statement coverage[A-Za-z\.*]\s*:\s*([^%]+)/.
  • pest --coverage --colors=never (PHP). Example: /^\s*Cov:\s*\d+\.\d+?%$/.
  • phpunit --coverage-text --colors=never (PHP). Example: /^\s*Lines:\s*\d+.\d+\%/.
  • gcovr (C/C++). Example: /^TOTAL.*\s+(\d+\%)$/.
  • tap --coverage-report=text-summary (NodeJS). Example: /^Statements\s*:\s*([^%]+)/.
  • nyc npm test (NodeJS). Example: /All files[^|]*\|[^|]*\s+([\d\.]+)/.
  • jest --ci --coverage (NodeJS). Example: /All files[^|]*\|[^|]*\s+([\d\.]+)/.
  • excoveralls (Elixir). Example: /\[TOTAL\]\s+(\d+\.\d+)%/.
  • mix test --cover (Elixir). Example: /\d+.\d+\%\s+\|\s+Total/.
  • JaCoCo (Java/Kotlin). Example: /Total.*?([0-9]{1,3})%/.
  • go test -cover (Go). Example: /coverage: \d+.\d+% of statements/.
  • .NET (OpenCover). Example: /(Visited Points).*\((.*)\)/.
  • .NET (dotnet test line coverage). Example: /Total\s*\|\s*(\d+(?:\.\d+)?)/.
  • tarpaulin (Rust). Example: /^\d+.\d+% coverage/.
  • Pester (PowerShell). Example: /Covered (\d+\.\d+%)/.

View code coverage history

To see the evolution of your project code coverage over time, you can view a graph or download a CSV file with this data.

  1. On the top bar, select Main menu > Projects and find your project.
  2. On the left sidebar, select Analytics > Repository.

The historic data for each job is listed in the dropdown list above the graph.

To view a CSV file of the data, select Download raw data (.csv).

Code coverage graph of a project over time

Code coverage data is also available at the group level.

Coverage check approval rule (PREMIUM)

You can implement merge request approvals to require approval by selected users or a group when merging a merge request would cause the project's test coverage to decline.

Follow these steps to enable the Coverage-Check MR approval rule:

  1. Set up a coverage regular expression for all jobs you want to include in the overall coverage value.
  2. Go to your project and select Settings > Merge requests.
  3. Under Merge request approvals, select Enable next to the Coverage-Check approval rule.
  4. Select the Target branch.
  5. Set the number of Approvals required to greater than zero.
  6. Select the users or groups to provide approval.
  7. Select Add approval rule.

Coverage-Check approval rule

Remove color codes from code coverage

Some test coverage tools output with ANSI color codes that aren't parsed correctly by the regular expression. This causes coverage parsing to fail.

Some coverage tools don't provide an option to disable color codes in the output. If so, pipe the output of the coverage tool through a small one line script that strips the color codes off.

For example:

lein cloverage | perl -pe 's/\e\[?.*?[\@-~]//g'

Pipeline badges

You can use pipeline badges to indicate the pipeline status and test coverage of your projects. These badges are determined by the latest successful pipeline.