프로젝트 수준 CI/CD 변수 API

Tier: Free, Premium, Ultimate Offering: GitLab.com, Self-Managed, GitLab Dedicated

프로젝트 변수 목록

프로젝트의 변수 목록을 가져옵니다.

GET /projects/:id/variables
속성 유형 필수 설명
id 정수/문자열 프로젝트의 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 정수/문자열 프로젝트의 ID 또는 URL 인코딩된 경로
key 문자열 변수의 key
filter 해시 아니오 사용 가능한 필터: [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 정수/문자열 프로젝트의 ID 또는 URL 인코딩된 경로
key 문자열 변수의 key; 255자 이상이어서는 안 됨; A-Z, a-z, 0-9, _만 허용됨
value 문자열 변수의 value
description 문자열 아니오 변수의 설명. 기본값: null. GitLab 16.2에서 도입됨
environment_scope 문자열 아니오 변수의 environment_scope. 기본값: *
masked 부울 아니오 변수가 마스킹된지 여부. 기본값: false
protected 부울 아니오 변수가 보호되는지 여부. 기본값: false
raw 부울 아니오 변수가 원시 문자열로 처리되는지 여부. 기본값: false. true인 경우 값의 변수는 확장되지 않습니다.
variable_type 문자열 아니오 변수의 유형; 사용 가능한 유형: 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-encoded path of the project
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 parameter details 참조
masked boolean No 변수가 마스킹되었는지 여부
protected boolean No 변수가 보호되었는지 여부
raw boolean No 변수가 원시 문자열로 취급되는지 여부. 기본값: false. true일 때 값의 변수는 expanded되지 않습니다.
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 integer/string Yes 프로젝트의 ID 또는 URL-encoded path of the project
key string Yes 변수의 key
filter hash No 사용 가능한 필터: [environment_scope]. filter parameter details 참조
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/variables/VARIABLE_1"

filter parameter

여러 변수가 동일한 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"