올챙이시절 기록소

Gitlab CI Variables 환경변수 알아보기 본문

2016/8월

Gitlab CI Variables 환경변수 알아보기

allroundplayer 2017. 10. 23. 17:46

ref : Gitlab CI > Variables


GitLab CI를 사용하여 Runner를 쓸 때,


기본적으로 세팅되어 있는 환경변수를 쓰면 편리한 경우가 있다



 ex ) 동일한 컨테이너를 쓰는데 현 프로젝트를 알아야 하는 경우


CI_PROJECT_NAME


 ex )  정규표현식으로 걸러진 tag에만 수행하도록 설계된 Pipeline에서 트리거가 걸린 Tag의 값을 확인할 때


CI_COMMIT_TAG


 ex )  채팅앱으로 Pipeline Status View 연계 링크에 필요한 Pipeline 번호를 확인할 때


CI_PIPELINE_ID

( 쉘에서  이렇게 "$CI_PIPELINE_ID" 변수의 값을 쓰는 것이다 )

·

·

·




여하튼, 여러가지 경우에 요긴하다


Gitlab은 문서가 정말 잘 만들어져 있어 자동화하기에 최고다


Predefined variables (Environment variables)

Some of the predefined environment variables are available only if a minimum version of GitLab Runner is used. Consult the table below to find the version of Runner required.


VariableGitLabRunnerDescription
CIall0.4Mark that job is executed in CI environment
CI_COMMIT_REF_NAME9.0allThe branch or tag name for which project is built
CI_COMMIT_REF_SLUG9.0all$CI_COMMIT_REF_NAME lowercased, shortened to 63 bytes, and with everything except 0-9 and a-zreplaced with -. No leading / trailing -. Use in URLs, host names and domain names.
CI_COMMIT_SHA9.0allThe commit revision for which project is built
CI_COMMIT_TAG9.00.5The commit tag name. Present only when building tags.
CI_CONFIG_PATH9.40.5The path to CI config file. Defaults to .gitlab-ci.yml
CI_DEBUG_TRACEall1.7Whether debug tracing is enabled
CI_DISPOSABLE_ENVIRONMENTall10.1Mark that job is executed in a disposable environment (something that is created only for this job and disposed of/destroyed after the execution - all executors except shell and ssh). If the environment is disposable, it is set to true, otherwise it is not defined at all.
CI_ENVIRONMENT_NAME8.15allThe name of the environment for this job
CI_ENVIRONMENT_SLUG8.15allA simplified version of the environment name, suitable for inclusion in DNS, URLs, Kubernetes labels, etc.
CI_ENVIRONMENT_URL9.3allThe URL of the environment for this job
CI_JOB_ID9.0allThe unique id of the current job that GitLab CI uses internally
CI_JOB_MANUAL8.12allThe flag to indicate that job was manually started
CI_JOB_NAME9.00.5The name of the job as defined in .gitlab-ci.yml
CI_JOB_STAGE9.00.5The name of the stage as defined in .gitlab-ci.yml
CI_JOB_TOKEN9.01.2Token used for authenticating with the GitLab Container Registry
CI_REPOSITORY_URL9.0allThe URL to clone the Git repository
CI_RUNNER_DESCRIPTION8.100.5The description of the runner as saved in GitLab
CI_RUNNER_ID8.100.5The unique id of runner being used
CI_RUNNER_TAGS8.100.5The defined runner tags
CI_PIPELINE_ID8.100.5The unique id of the current pipeline that GitLab CI uses internally
CI_PIPELINE_TRIGGEREDallallThe flag to indicate that job was triggered
CI_PIPELINE_SOURCE10.0allThe source for this pipeline, one of: push, web, trigger, schedule, api, external. Pipelines created before 9.5 will have unknown as source
CI_PROJECT_DIRallallThe full path where the repository is cloned and where the job is run
CI_PROJECT_IDallallThe unique id of the current project that GitLab CI uses internally
CI_PROJECT_NAME8.100.5The project name that is currently being built (actually it is project folder name)
CI_PROJECT_NAMESPACE8.100.5The project namespace (username or groupname) that is currently being built
CI_PROJECT_PATH8.100.5The namespace with project name
CI_PROJECT_PATH_SLUG9.3all$CI_PROJECT_PATH lowercased and with everything except 0-9 and a-z replaced with -. Use in URLs and domain names.
CI_PROJECT_URL8.100.5The HTTP address to access project
CI_REGISTRY8.100.5If the Container Registry is enabled it returns the address of GitLab's Container Registry
CI_REGISTRY_IMAGE8.100.5If the Container Registry is enabled for the project it returns the address of the registry tied to the specific project
CI_REGISTRY_PASSWORD9.0allThe password to use to push containers to the GitLab Container Registry
CI_REGISTRY_USER9.0allThe username to use to push containers to the GitLab Container Registry
CI_SERVERallallMark that job is executed in CI environment
CI_SERVER_NAMEallallThe name of CI server that is used to coordinate jobs
CI_SERVER_REVISIONallallGitLab revision that is used to schedule jobs
CI_SERVER_VERSIONallallGitLab version that is used to schedule jobs
CI_SHARED_ENVIRONMENTall10.1Mark that job is executed in a shared environment (something that is persisted across CI invocations like shell or ssh executor). If the environment is shared, it is set to true, otherwise it is not defined at all.
ARTIFACT_DOWNLOAD_ATTEMPTS8.151.9Number of attempts to download artifacts running a job
GET_SOURCES_ATTEMPTS8.151.9Number of attempts to fetch sources running a job
GITLAB_CIallallMark that job is executed in GitLab CI environment
GITLAB_USER_ID8.12allThe id of the user who started the job
GITLAB_USER_EMAIL8.12allThe email of the user who started the job
GITLAB_USER_LOGIN10.0allThe login username of the user who started the job
GITLAB_USER_NAME10.0allThe real name of the user who started the job
RESTORE_CACHE_ATTEMPTS8.151.9Number of attempts to restore the cache running a job


Comments