> For the complete documentation index, see [llms.txt](https://docs.harubuilds.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.harubuilds.dev/ci-cd/ji-ben-gai-nian.md).

# 基本概念

* 預設必須使用的檔案名稱：`.gitlab-ci.yml`
* 主要結構
  * **stages**：決定執行的順序，可以自行定義各階段名稱，常見的有 build, test, deploy
  * **jobs**：在每個階段要執行的任務內容 (必須註明吻合的階段名稱)，同一個 stage 的 jobs 會同時執行。
  * **script**：定義 Job 的執行指令，不一定只有一條指令，它通常是一組 shell command。
* Pipeline 觸發的方式：push, merge request, schedule, ... etc.
* **Runner**：執行 pipeline 的 agent，當 pipeline 被觸發，就會去領取 GitLab 準備好的 job 開始執行。
* Variables：有 GitLab 提供的變數，也可以有自定義的變數。
* Expression：分為一般的 expression，和需要 `$[[]]` 的 inputs expression。一般 expression 用於評估 CI/CD variables；inputs expression 用於引用 CI/CD inputs。\
  \
  variable expression

  ```yml
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'
  ```

  \
  inputs expression

  ```yml
  spec:
    inputs:
      environment:
        default: staging

  deploy:
    script:
      - deploy $[[ inputs.environment ]]
  ```
* **Components (Templates)**：可重複使用的 CI/CD 設定模組（template）。把常用的內容分離成一個單獨的 `yml` 檔案，在不同專案的 `.gitlab-ci.yml` 都可以用 include 引入使用。\
  \
  components/deploy.yml

  ```yml
  spec:
    inputs:
      environment:
        default: staging

  deploy:
    stage: deploy
    script:
      - deploy $[[ inputs.environment ]]
  ```

  \
  其他專案

  ```yml
  include:
    - component: my-group/deploy@v1
      inputs:
        environment: production
  ```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.harubuilds.dev/ci-cd/ji-ben-gai-nian.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
