프로젝트 수준 CI/CD 변수 API
Tier: Free, Premium, Ultimate
Offering: GitLab.com, Self-managed, GitLab Dedicated
프로젝트 변수 디렉터리
프로젝트의 변수 디렉터리을 가져옵니다.
GET /projects/:id/variables
| 속성 | 유형 | 필수 | 설명 | 
|---|---|---|---|
id
 | integer/string | Yes | 프로젝트의 ID 또는 URL 인코딩된 경로 | 
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/variables"
[
    {
        "variable_type": "env_var",
        "key": "TEST_VARIABLE_1",
        "value": "TEST_1",
        "protected": false,
        "masked": true,
        "raw": false,
        "environment_scope": "*",
        "description": null
    },
    {
        "variable_type": "env_var",
        "key": "TEST_VARIABLE_2",
        "value": "TEST_2",
        "protected": false,
        "masked": false,
        "raw": false,
        "environment_scope": "*",
        "description": null
    }
]
단일 변수 가져오기
단일 변수의 세부 정보를 가져옵니다. 동일한 키를 가진 여러 변수가 있는 경우 filter를 사용하여 올바른 environment_scope를 선택합니다.
GET /projects/:id/variables/:key
| 속성 | 유형 | 필수 | 설명 | 
|---|---|---|---|
id
 | integer/string | Yes | 프로젝트의 ID 또는 URL 인코딩된 경로 | 
key
 | string | Yes | 변수의 key
 | 
filter
 | hash | No | 사용 가능한 필터: [environment_scope]. filter 매개변수 세부 정보를 참조하십시오.
 | 
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/variables/TEST_VARIABLE_1"
{
    "key": "TEST_VARIABLE_1",
    "variable_type": "env_var",
    "value": "TEST_1",
    "protected": false,
    "masked": true,
    "raw": false,
    "environment_scope": "*",
    "description": null
}
변수 생성
새 변수를 생성합니다. 동일한 key를 가진 변수가 이미 존재하는 경우, 새 변수는 다른 environment_scope를 가져야 합니다. 그렇지 않으면 GitLab은 VARIABLE_NAME has already been taken과 유사한 메시지를 반환합니다.
POST /projects/:id/variables
| 속성 | 유형 | 필수 | 설명 | 
|---|---|---|---|
id
 | integer/string | Yes | 프로젝트의 ID 또는 URL 인코딩된 경로 | 
key
 | string | Yes | 변수의 key; 최대 255자여야 하며 A-Z, a-z, 0-9, _만 허용됨
 | 
value
 | string | Yes | 변수의 value
 | 
description
 | string | No | 변수의 설명. 기본값: null. GitLab 16.2에서 소개됨
 | 
environment_scope
 | string | No | 변수의 environment_scope. 기본값: *
 | 
masked
 | boolean | No | 변수가 마스킹된지 여부. 기본값: false
 | 
protected
 | boolean | No | 변수가 보호되는지 여부. 기본값: false
 | 
raw
 | boolean | No | 변수가 원시 문자열로 처리되는지 여부. 기본값: false. true인 경우 값이 확장되지 않음
 | 
variable_type
 | string | No | 변수의 유형. 사용 가능한 유형: env_var (기본값) 및 file
 | 
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
     "https://gitlab.example.com/api/v4/projects/1/variables" --form "key=NEW_VARIABLE" --form "value=new value"
{
    "variable_type": "env_var",
    "key": "NEW_VARIABLE",
    "value": "new value",
    "protected": false,
    "masked": false,
    "raw": false,
    "environment_scope": "*",
    "description": null
}
변수 업데이트
프로젝트의 변수를 업데이트합니다. 동일한 키를 가진 여러 변수가 있는 경우 filter를 사용하여 올바른 environment_scope를 선택합니다.
PUT /projects/:id/variables/:key
| 속성 | 유형 | 필수 | 설명 | 
|---|---|---|---|
id
 | integer/string | Yes | 프로젝트의 ID 또는 URL 인코딩된 경로 | 
key
 | string | Yes | 변수의 key
 | 
value
 | string | Yes | 변수의 value
 | 
description
 | string | No | 변수의 설명. 기본값: null. GitLab 16.2에서 소개됨
 | 
environment_scope
 | string | No | 변수의 environment_scope
 | 
filter
 | hash | No | 사용 가능한 필터: [environment_scope]. filter 매개변수 세부 정보를 참조하십시오.
 | 
masked
 | boolean | No | 변수가 마스킹된지 여부 | 
protected
 | boolean | No | 변수가 보호되는지 여부 | 
raw
 | boolean | No | 변수가 원시 문자열로 처리되는지 여부. 기본값: false. true인 경우 값이 확장되지 않음
 | 
variable_type
 | string | No | 변수의 유형. 사용 가능한 유형: env_var (기본값) 및 file
 | 
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" \
     "https://gitlab.example.com/api/v4/projects/1/variables/NEW_VARIABLE" --form "value=updated value"
{
    "variable_type": "env_var",
    "key": "NEW_VARIABLE",
    "value": "updated value",
    "protected": true,
    "masked": false,
    "raw": false,
    "environment_scope": "*",
    "description": "null"
}
변수 삭제
프로젝트의 변수를 삭제합니다. 동일한 키를 가진 여러 변수가 있는 경우 filter를 사용하여 올바른 environment_scope를 선택합니다.
DELETE /projects/:id/variables/:key
| 속성 | 유형 | 필수 | 설명 | 
|---|---|---|---|
id
 | 정수/문자열 | 예 | ID 또는 프로젝트의 URL-인코딩된 경로 | 
key
 | 문자열 | 예 | 변수의 key
 | 
filter
 | 해시 | 아니요 | 사용 가능한 필터: [environment_scope]. filter 매개변수 세부정보 참조
 | 
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/variables/VARIABLE_1"
filter 매개변수
- GitLab 13.2에서 도입됨.
 - GitLab 13.4에서 피처 플래그가 제거됨.
 
동일한 key를 가진 여러 변수가 있는 경우 GET, PUT, 또는 DELETE 요청은 다음과 같이 반환될 수 있습니다.
제공된 매개변수로 여러 변수가 있습니다. 'filter[environment_scope]'를 사용하세요.
filter[environment_scope]를 사용하여 일치하는 environment_scope 속성을 가진 변수를 선택합니다.
예를 들어:
- 
GET:
curl --globoff --header "PRIVATE-TOKEN: <your_access_token>" \ "https://gitlab.example.com/api/v4/projects/1/variables/SCOPED_VARIABLE_1?filter[environment_scope]=production" - 
PUT:
curl --request PUT --globoff --header "PRIVATE-TOKEN: <your_access_token>" \ "https://gitlab.example.com/api/v4/projects/1/variables/SCOPED_VARIABLE_1?value=scoped-variable-updated-value&environment_scope=production&filter[environment_scope]=production" - 
DELETE:
curl --request DELETE --globoff --header "PRIVATE-TOKEN: <your_access_token>" \ "https://gitlab.example.com/api/v4/projects/1/variables/SCOPED_VARIABLE_1?filter[environment_scope]=production" 
도움말