Updated on 2024-05-30 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 for a task on the basic information page.
  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: CodeArts 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 number (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.
    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 Actions

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 Download Code

- 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

- yarn

Build with Yarn

Using YAML to Build with Yarn

- go

Build with Go

Using YAML to Configure a Build with Go

- gulp

Build with Gulp

Using YAML to Build with Gulp

- grunt

Build with Grunt

Using YAML to Build with Grunt

- php

Build in PHP

Using YAML to Build in PHP

- gnu_arm

Build with GNU Arm

Using YAML to Build with GNU Arm

- python

Build with Setuptools

Build with PyInstaller

Use Python for build

Using YAML to Configure a Build with Setuptools

Using YAML to Configure a Build with PyInstaller

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 Build with Ant

- cmake

Build with CMake

Using YAML to Configure a CMake Build

- mono

Build with Mono

Using YAML to Configure a Mono Build

- flutter

Build with Flutter

Using YAML to Build with Flutter

- sbt

Build with sbt

Using YAML to Build with sbt

- android

Build with Android

Using YAML to Configure an Android Build

- android_sign

Sign Android APK

Using YAML to Sign Android APK

- quick_app

Build Android Quick App

Using YAML to Build an Android Quick App

- bazel

Build with Bazel

Using YAML to Configure a Bazel Build

- grails

Build with Grails

Using YAML to Build with Grails

- build_image

Build an image and push it to SWR

Using YAML to Build an Image and Push It to SWR

- upload_obs

Upload files to OBS

Using YAML to Upload Files to OBS

- download_file

Download files

Using YAML to Download Files

- upload_artifact

Upload a binary package to the repository

Using YAML to Upload a Binary Package to a Repository

- download_artifact

Download binary packages

Using YAML to Download Binary Packages

- docker

Run Docker commands

Using YAML to Run Docker Commands