يمكن تعيين متغيرات Gitlab في عدة أماكن:
- في إعدادات المجموعة
- في إعدادات المشروع
- داخل .gitlab-ci.yml
في هذه الحالة ، يمكن تعيين المتغيرات في إعدادات المجموعات والمشروع كـ "ملف" أو "متغير عادي" والتحقق من المربعين "المحمي" و "القناع".

لنبدأ بالميراث البسيط وسنصبح أكثر تعقيدًا بشكل تدريجي.
يمكن العثور على قائمة نهائية بمستويات الأولوية في نهاية الوثيقة.
, , .

image: busybox:latest
variables:
GIT_STRATEGY: none
echo:
stage: test
script:
- echo $MSG
$ echo $MSG
B
B, .
.gitlab-ci.yml []
: , .
c

2 , $MSG.
image: busybox:latest
variables:
GIT_STRATEGY: none
MSG: "Custom in global .gitlab-ci.yml"
echo:
stage: test
script:
- echo $MSG
echo with var:
stage: test
variables:
MSG: "Custom in job .gitlab-ci.yml"
script:
- echo $MSG
.gitlab-ci.yml []
2 . .gitlab-ci.yml.
c

image: busybox:latest
variables:
GIT_STRATEGY: none
MSG: "Custom in global .gitlab-ci.yml"
echo:
stage: test
script:
- echo $MSG
echo with var:
stage: test
variables:
MSG: "Custom in job .gitlab-ci.yml"
script:
- echo $MSG
! , .gitlab-ci.yml .
c
.

. , , .gitlab-ci.yml, .
image: busybox:latest
variables:
GIT_STRATEGY: none
MSG: "Custom in global .gitlab-ci.yml"
echo:
stage: test
script:
- echo $MSG
echo with var:
stage: test
variables:
MSG: "Custom in job .gitlab-ci.yml"
script:
- echo $MSG
–
– Null
c

image: busybox:latest
variables:
GIT_STRATEGY: none
MSG: "Custom in global .gitlab-ci.yml"
echo:
stage: test
script:
- echo $MSG
echo with var:
stage: test
variables:
MSG: "Custom in job .gitlab-ci.yml"
script:
- echo $MSG
project-2 project-3
.
c

.gitlab-ci.yml
variables:
MSG: "With include .gitlab-ci.yml"
include:
- project: how-is-gitlab-ci-inherit-environment-variables/z/y/project-3
file: '.gitlab-ci.yml'
project-2 project-3.
C : , .
c

variables:
MSG: "With include .gitlab-ci.yml"
include:
- project: how-is-gitlab-ci-inherit-environment-variables/z/y/project-3
file: '.gitlab-ci.yml'
:
- ( )
- .gitlab-ci.yml
النقطة الأكثر وضوحًا هي أن القاعدة "كلما كان المتغير أقرب إلى الشفرة ، زادت أهميته" تعمل أولاً للمجموعات ، ثم نفس القاعدة للمتغيرات داخل .gitlab-ci.yml ، ولكن فقط بشرط عدم تحديد المتغيرات في المجموعات .
علاوة على ذلك ، هناك مكان مهم هو فهم أن المساحة العالمية للنواة والمُستبعدة .gitlab-ci.yml شائعة. والملف الذي يحدث فيه التضمين له الأسبقية.