Updated on 2024-11-21 GMT+08:00

Configuring the Code Download

In this action, you set the download mode for pulling code from the repository during the build process.

Build on GUI

You can specify a source version with a code repository tag or commit ID. Besides, you can enable auto update of submodules and Git Large File Storage (LFS) for your build.

The Configure Code Download action is preset. Set the parameters according to Table 1.

Table 1 Parameters for configuring the code download

Parameter

Description

Specify Repository Tag or Commit ID

Specify whether to specify a tag or a commit ID when running a build task.

  • Do Not specify: All code is pulled for your build.
  • Tag: Only the code with the specified tag is pulled for your build. When you run the build task, a dialog box will appear prompting you to enter a tag.

    A tag marks a point in a code repository. If you select Repo as the code source, you can create a tag by referring to Managing Tags. When using a third-party code repository as the source, you need to create a tag within that repository.

  • Commit ID: Only the code with the specified commit ID is pulled for your build. When you run the build task, a dialog box will appear prompting you to enter a commit ID.

    A commit ID is the number generated when the code is committed. For example, the commit ID in a CodeArts Repo repository is shown in Figure 1.

    Figure 1 Commit ID

Clone Depth

Optional.

The clone depth is the number of recent commits that will be cloned. A larger value indicates more commits will be fetched. The clone depth must be a positive integer. The recommended maximum value is 25.

For example, setting the clone depth to 5 instructs the system to fetch only the five most recent commits, but no earlier records.

Auto Update

A submodule is a Git tool used to manage shared repositories for higher team efficiency. Submodules allow you to keep a shared repository as a subdirectory of your repository. You can isolate and reuse repositories, and pull latest changes from or push commits to shared repositories. For details, see Submodules.

  • Enabled: If the code repository contains submodules, the system automatically pulls the code from the submodule repository during a build.
  • Disabled: The system does not automatically pull the code of the submodule repository.

Enable Git LFS

Determine whether to enable Git LFS to pull all files, including large files, such as audios, videos, and images, during a build. By default, these files are not pulled.

Build with Code (Downloading Code from a Single Repo)

Modify the code in the PRE_BUILD block in Creating a YAML File for Your Code-based Build by referring to the following sample code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
version: 2.0 # The value must be 2.0.
steps:
  PRE_BUILD:
    - checkout:
        name: checkout
        inputs:
          scm: codehub # Code source: CodeArts Repo only
          url: xxxxxxxxx # This refers to the SSH address of the repository that the code is pulled from.
          branch: ${codeBranch} # Mandatory at any time and can be parameterized.
          commit: ${commitId}
          lfs: true
          submodule: true
          depth: 100
          tag: ${tag}
          path: test
Table 2 Parameters in the sample code for downloading a single repository

Parameter

Type

Description

scm

String

Enter a code source. Currently, only CodeArts Repo is supported. If this parameter is not configured in the YAML file, the code repository information configured in the build task will be used.

The default value is codehub.

url

String

Enter the SSH address of the code repository from which the code will be pulled.

branch

String

Specify the branch from which to pull the code.

You can use ${codeBranch} to reference this parameter.

commit

String

Optional. If needed, you can enter a commit ID to indicate the specific version of the source code to be pulled for your build.

You can also use ${commitId} to reference this parameter.

tag

String

Optional. If needed, you can enter a tag to indicate the specific version of the source code to be pulled for your build.

You can also use ${tag} to reference this parameter. If you provide both the commit ID and tag, the build using the commit ID will be run first.

depth

Int

Optional. Shallow clone depth. When a commit ID is specified for builds, depth must be greater than or equal to the depth of the commit ID.

The default value is 1.

submodule

Bool

Optional. Specify whether to pull the submodules.

  • true: Pull.
  • false: Do not pull.

The default value is false.

lfs

Bool

Optional. Specify whether to enable Git LFS.

  • true: Enable.
  • false: Disable.

By default, CodeArts Build does not pull large files such as audios, videos, and images. You can enable Git LFS to pull all files. The default value is false.

path

String

Optional. Sub-path for cloning: The code is downloaded to the sub-path.

Build with Code (Downloading Code from Multiple Repos via Manifest)

In scenarios such as Android and HarmonyOS, hundreds or even thousands of code repositories need to be integrated at the same time during one build. The efficiency of integrating and downloading multiple code repositories is critical.

CodeArts Build integrates the Repo download tool. You only need to perform simple configurations to download multiple code repositories. Currently, this feature only applies to CodeArts Repo repositories.

Modify the code in the PRE_BUILD block in Creating a YAML File for Your Code-based Build by referring to the following sample code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
version: 2.0 # The value must be 2.0.
steps:
  PRE_BUILD:
  - manifest_checkout:
      name: "manifest"
      inputs:
        manifest_url: "https://example.example.example.example.example.com/xx/manifest.git"
        manifest_branch: "master"
        manifest_file: "default.xml"
        path: "dir/dir02"
        repo_url: "https://example.example.example.example.example.com/xx/git-repo.git"
        repo_branch: "master"
        username: "someone"
        password: "${PASSWD}"
Table 3 Parameters in the sample code for downloading multiple repositories via Manifest

Parameter

Type

Description

name

String

Optional. Enter the action name. The default value is manifest_checkout.

manifest_url

String

Enter the address of a Manifest repository that includes an XML file.

manifest_branch

String

Optional. Enter the Manifest branch or revision. The default value is HEAD.

manifest_file

String

Optional. Manifest file path. The default value is default.xml.

path

String

Optional. Download path of all sub-repositories of the custom Manifest file, which is the relative path of the working path.

The path cannot start with a slash (/) and cannot contain any period (.). The default value is the working path.

repo_url

String

Optional. Enter the address of the CodeArts Repo repository. The default value is https://gerrit.googlesource.com/git-repo.

repo_branch

String

Optional. Enter the branch of the CodeArts Repo repository. The default value is stable.

username

String

Optional. Enter the username used for downloading the repository. This parameter is mandatory for private repositories.

password

String

Optional. Enter the HTTPS password used for downloading the repository. This parameter is mandatory for private repositories.

  1. The repositories defined in manifest_file must be of the same code source.
  2. manifest_url and manifest_file must use the same code source. For private repositories, the account indicated by the username and password you use must have been granted the download permission.
  3. You must have been granted the download permission for the CodeArts Repo repository specified by repo_url (the repository can either be open-source or private, but configured with account and password).
  4. If the optional parameters mentioned above are left empty, default values will be used.
  5. When using private repositories, you are advised to configure the username and password using private build parameters. For details, see Configuring Parameters.