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

Uploading Files to OBS

CodeArts Build allows you to upload build products to OBS. You can use this build action as required.

For details about the restrictions on using OBS, see Restrictions and Limitations.

Preparations

To upload files to OBS of other users, perform the following operations.
  1. Access the CodeArts Build Homepage from the project list.
  2. In the navigation pane, choose Settings > General > Service Endpoints.
  3. Select IAM user from the Create Endpoint drop-down list box. In the displayed dialog box, enter the following information and click Confirm.
    • Service Endpoint Name: Assign a custom name to the endpoint. Enter a maximum of 256 characters, including letters, digits, hyphens (-), underscores (_), periods (.), and spaces.
    • Access key ID (AK) and secret access key (SK) are used like passwords to authenticate users who make API requests.

      On the CodeArts Build homepage, click Console, hover the cursor on the username in the upper right corner, and choose My Credentials from the drop-down list. In the navigation pane on the left, choose Access Keys to create a user key.

Build on GUI

Add Upload Files to OBS, when configuring build actions. Set the parameters according to Table 1.

Table 1 Parameters for uploading files to OBS

Parameter

Description

Action Name

Assign a custom name to the build action. The name can contain:

  • Letters, digits, hyphens (-), underscores (_), commas (,), semicolons (;), colons (:), periods (.), slashes (/), and parentheses.
  • 1 to 128 characters.

Authorized User

Select the user. Your files will be pushed to the user's OBS.

  • Current: Upload files to an OBS bucket of the current user.
  • Other: Upload files to OBS of a specific user by specifying an IAM account.

IAM Account

Expand the drop-down list and select the service endpoint created in Preparations for the specific IAM account. Then, use the service endpoint to push the files to the user's OBS.

This parameter is mandatory when Authorized User is set to Other.

Build Directory

Directory for storing build results. If no file name is specified for OBS storage, use wildcard characters to upload multiple files. Example: **/target/*.?ar uploads all JAR and WAR packages built with Maven.

Examples:
  • *.class: Matches files whose names end with .class in the current directory.
  • **/*.class: Recursively matches all files whose names end with .class in the current directory.
  • test/a??.java: Matches Java files whose names start with a followed by two characters in the test directory.
  • **/test/**/XYZ*: Recursively matches all files whose parent directory is test and whose names start with XYZ, for example, abc/test/def/ghi/XYZ123.

Bucket Name

Name of the target OBS bucket. (Cross-region upload is not supported.)

OBS Directory

Optional.

Directory for storing build results on OBS (for example, application/version/). You can leave this parameter blank or enter ./ to store build results to the OBS root directory.

File Name

Optional.

Enter the name (without the directory) that the resulting build file will be stored as in OBS.
  • If leave it as blank, you can upload multiple files and use the build product file name as the name it will be stored as in OBS.
  • If you do not leave it as blank, you can upload only one file, such as application.jar.

Headers

Optional.

Add one or more custom response headers during the file upload. The headers will be included in the response to download objects or query the object metadata.

For example, you can set the key to x-frame-options and value to false to prevent web pages stored in OBS from being embedded into by third-party web pages.

Continue After Failure

Specify whether to proceed after the current action fails by setting the parameter to either Yes or No.

Build with Code

Modify the code in the 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:
  BUILD:
    - upload_obs:
          inputs:
            artifact_path: "**/target/*.?ar"
            bucket_name: codecitest-obs
            obs_directory: "./"
          #   artifact_dest_name: ""
          #   upload_directory: true
          #   headers:
          #     x-frame-options: true
          #     test: test
          #     commit: ${commitId}
           ignore_fail: true
Table 2 Parameters in the sample code

Parameter

Type

Description

artifact_path

String

Optional.

Directory for storing build results. If no file name is specified for OBS storage, use wildcard characters to upload multiple files. Example: **/target/*.?ar uploads all JAR and WAR packages built with Maven.

Examples:
  • *.class: Matches files whose names end with .class in the current directory.
  • **/*.class: Recursively matches all files whose names end with .class in the current directory.
  • test/a??.java: Matches Java files whose names start with a followed by two characters in the test directory.
  • **/test/**/XYZ*: Recursively matches all files whose parent directory is test and whose names start with XYZ, for example, abc/test/def/ghi/XYZ123.

The default value is bin/*.

bucket_name

String

Name of the target OBS bucket. (Cross-region upload is not supported.)

obs_directory

String

Optional.

Directory for storing build results on OBS (for example, application/version/). You can leave this parameter blank or enter ./ to store build results to the OBS root directory.

The default value is ./.

artifact_dest_name

String

Optional.

Enter the name (without the directory) that the resulting build file will be stored as in OBS.
  • If leave it as blank, you can upload multiple files and use the build product file name as the name it will be stored as in OBS.
  • If you do not leave it as blank, you can upload only one file, such as application.jar.

upload_directory

Bool

Optional.

Specify whether to enable the function of uploading folders.

  • true: The folder of the build product is also uploaded.
  • false: All matched build products are uploaded to obs_directory in tile mode.

The default value is false.

headers

Map

Optional.

Add one or more custom response headers during the file upload. The headers will be included in the response to download objects or query the object metadata.

For example, you can set the value of x-frame-options to false to prevent web pages stored in OBS from being embedded into by third-party web pages.

ignore_fail

String

Whether to proceed after the current action fails.
  • true: Yes
  • Empty: No