Updated on 2023-12-21 GMT+08:00

Introducing the YAML File Structure

YAML File Example

In this example, the Maven build template is executed using the YAML file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
version: 2.0 # The value must be 2.0.
params: # Build parameters, which can be referenced during a build.
  - name: paramA
    value: valueA
  - name: paramB
    value: valueB
env: # This parameter is optional but has the highest priority. The host specifications and type (if any) defined here will be used instead of those you configured on the basic information page for a task.
  resource:
    type: docker # The agent pool type can be: Docker, Linux, macOS or custom ones.
    arch: X86 # The host type of the build environment can be: x86 or Arm.
    class: 8 vCPUs | 16 GB # The specification can be: 2 vCPUs | 8 GB, 4 vCPUs | 8 GB, 8 vCPUs | 16 GB, 16 vCPUs | 32 GB, or 16 vCPUs | 64 GB. This parameter is not required when the agent pool type is set to a custom one.
    pool: Mydocker # Agent pool name. This parameter is required when the agent pool type is set to a custom one.
steps:
  PRE_BUILD:
    - checkout:
        name: Download Code # This field is optional.
       inputs: # Action parameters
          scm: codehub # Code source: Repo only
          url: xxxxxxxxx # SSH address for the URL to pull code
          branch: ${codeBranch} # Pulled code branch, which can be parameterized.
    - sh:
        inputs:
          command: echo ${paramA}
  BUILD:
    - maven: # Action keyword. Only specified keywords are supported.
	name: maven build # Optional
	image: xxx # You can customize the image path. For details, see the following description.
	inputs:
	  command: mvn clean package
    - upload_artifact:
	inputs:
          path: "**/target/*.?ar"

The .yml file consists of four parts:

  • Version: In the example file, version is set to 2.0. The version number is mandatory and unique.
  • Build environment (env): The sample file defines the resource pool type, build environment host type, and host specifications.
  • Build parameters (params): Optional. paramA and paramB are defined in the sample file and can be referenced during the build process. Build parameters created during task configuration are preferentially used.
  • Build actions (steps): In the example file, there are three phases under the steps level:
    • PRE_BUILD: used to prepare for building, for example, downloading code and executing shell.
    • BUILD: used to build mainstream projects such as Maven, npm, Go, Python, Ant, CMake, Mono, sbt, Android and Bazel. After the build is complete, you can define post-build operations, such as creating images and uploading them to SWR, uploading files to OBS, downloading files, uploading binary packages to the specified repository, downloading binary packages, and running Docker commands.
    • After the build.yml file is defined, strictly comply with the file storage path rules and place the build.yml file in the .cloudbuild path.

    • The image can be in either of the following formats:
      • cloudbuild@maven3.5.3-jdk8-open, which starts with cloudbuild, uses @ as the separator, and is followed by the default image provided by CodeArts Build.
      • Complete SWR image path, for example, swr.example.example.com/codeci_test/demo:141d26c455abd6d7xxxxxxxxxxxxxxxxxxxx.

Build Procedure

In steps, there are two phases: PRE_BUILD and BUILD. Each phase can define a series of build steps. For details, see the following table.

PRE_BUILD

Description

Operation Guide

- checkout

Download code

Using YAML to Configure Code Download

- sh

Run Shell commands

Using YAML to Configure and Execute Shell Commands

BUILD

Description

Operation Guide

- maven

Build with Maven

Using YAML to Configure a Maven Build

- npm

Build with npm

Using YAML to Configure an npm Build

- go

Use Go for build

Using YAML to Configure a Build with Go

- python

Use Python for build

Using YAML to Configure a Python Build

- gradle

Build with Gradle

Using YAML to Configure a Gradle Build

- ant

Build with Ant

Using YAML to Configure an Ant Build

- cmake

Build with CMake

Using YAML to Configure a CMake Build

- mono

Build with Mono

Using YAML to Configure a Mono Build

- sbt

Build with sbt

Using YAML to Configure an sbt Build

- android

Build with Android

Using YAML to Configure an Android Build

- bazel

Build with Bazel

Using YAML to Configure a Bazel Build

- build_image

Create container images and upload them to SWR

Using YAML to Create an Image and Upload It to SWR

- upload_obs

Upload a file to OBS

Using YAML to Upload Files to OBS

- download_file

Download a file

Using YAML to Download Files

- upload_artifact

Upload the binary package to the repository

Using YAML to Upload Binary Packages to a Repository

- download_artifact

Download the binary package

Using YAML to Download Binary Packages

- docker

Run Docker commands

Using YAML to Run Docker Commands