388.md 1.4 KB
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
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 33 34 35 36 37 38 39 40 41 42 43
# Validate the `.gitlab-ci.yml` (API)

> 原文:[https://docs.gitlab.com/ee/api/lint.html](https://docs.gitlab.com/ee/api/lint.html)

# Validate the `.gitlab-ci.yml` (API)[](#validate-the-gitlab-ciyml-api "Permalink")

在 GitLab 8.12 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/5953) .

检查您的`.gitlab-ci.yml`文件是否有效.

```
POST /ci/lint 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `content` | string | yes | the `.gitlab-ci.yaml` content |

```
curl --header "Content-Type: application/json" "https://gitlab.example.com/api/v4/ci/lint" --data '{"content": "{ \"image\": \"ruby:2.6\", \"services\": [\"postgres\"], \"before_script\": [\"bundle install\", \"bundle exec rake db:create\"], \"variables\": {\"DB_NAME\": \"postgres\"}, \"types\": [\"test\", \"deploy\", \"notify\"], \"rspec\": { \"script\": \"rake spec\", \"tags\": [\"ruby\", \"postgres\"], \"only\": [\"branches\"]}}"}' 
```

请务必复制并粘贴`.gitlab-ci.yml`的确切内容,因为 YAML 对于缩进和空格非常挑剔.

响应示例:

*   有效内容:

    ```
    {  "status":  "valid",  "errors":  []  } 
    ```

*   无效的内容:

    ```
    {  "status":  "invalid",  "errors":  [  "variables config should be a hash of key value pairs"  ]  } 
    ```

*   没有 content 属性:

    ```
    {  "error":  "content is missing"  } 
    ```