---
url: /en/build/quick-start.md
description: >
  Step-by-step tutorial to create and run your first Cloud Native Build
  pipeline, including creating a repository, writing a .cnb.yml configuration
  file, and setting up a practical PR quality-gate pipeline.
---
`Cloud Native Build` provides out-of-the-box CI/CD capabilities.
The core concept is **declarative configuration**: define a series of
**tasks** to be executed automatically when specific **events** occur on
specific **branches**.

This guide covers two tasks:

1. **Add and run your first pipeline with NPC**: skip manual config and
   let CodeBuddy get your first pipeline running fast
2. **Write a practical PR pipeline**: Learn to configure a common pipeline for code quality gating

## Part 1: Add Your First Pipeline with CodeBuddy

CodeBuddy is an NPC (automation agent) deeply integrated with the platform and familiar
with the `.cnb.yml` pipeline syntax. No need to write config by hand or click through the
WebIDE step by step — just tell CodeBuddy what you want in a comment and it runs your
first pipeline for you.

### Step 1: Prepare a Repository

If you don't have a code repository, create an **empty repository** under your
organization first. It hosts your pipeline runs.

### Step 2: Ask CodeBuddy to Add a Pipeline

Open an Issue (or a Pull Request) in the repository, enable **Work Mode**,
then `@CodeBuddy` and describe what you want:

```text
@CodeBuddy Add a pipeline to the main branch that runs when code is pushed and outputs "hello world"
```

CodeBuddy handles the rest for you:

1. Generates `.cnb.yml` at the repo root — declaring a task that runs on pushes to
   `main` and outputs `hello world`
2. Commits and pushes the config, triggering the pipeline
3. Reports the execution result back in the current comment

### Step 3: View the Pipeline Execution Results

Once the build starts, return to your repository homepage and open the
`Cloud Native Build` tab to see all build records. Click the latest one
(triggered by the `push` event) to view detailed logs and status.

Congratulations! You've completed your first CI/CD practice with CodeBuddy —
no manual config needed at all.

:::: tip Note
The `.cnb.yml` generated above is equivalent to what you would write by hand;
its full syntax is explained in Part 2.
::::

## Part 2: Write a Practical PR Validation Pipeline

Now let's implement a more practical scenario: **Configure a Pull Request pipeline for the `main` branch
to automatically perform code checks (lint) and tests (test), and notify the team upon failure.**

### 1. Define the Branch, Event and Tasks

Specify the target branch (`main`) and the event (`pull_request`),
then run code checks (lint) and tests (test) in sequence in `stages`.

### 2. Define Failure Handling

If **any task** in `stages` fails, use `failStages` to automatically execute alert tasks.
Here is a complete PR checking pipeline:

```yaml title=".cnb.yml"
main:
  pull_request:
    - name: pr-check
      stages:
        - name: lint
          script: echo "Running linting tools..."
        - name: test
          script: echo "Running test suites..."
      failStages:
        - name: notify-team
          script: echo "Notifying the chat group that the PR check failed!"
```

**Pipeline Execution Logic:**

1. Listen for `pull_request` events on the `main` branch.
2. Start the `pr-check` pipeline.
3. Execute the tasks in `stages` in order (lint → test).
4. If all tasks succeed, the pipeline status is marked as passed.
5. If any task fails, abort immediately and execute the tasks in `failStages` instead.

## Next Steps

* 🔧 **Dive Deeper into Configuration**: Check out the [Configuration Details](./configuration.md)
  to explore more advanced features.
* 📖 **Master the Full Syntax**: Go to the [Syntax Guide](./grammar.md) to learn about all configuration items.
* 🚀 **Reference Real-World Examples**: Need more inspiration? Visit [Best Practices](https://cnb.cool/examples/showcase)
  to fork sample repositories or reuse their configurations to quickly customize your pipeline.
