gitlab-ci详细说明
⽂章⽬录
概念
从 Gitlab 8.0 开始,Gitlab CI 就已经集成在 Gitlab 中,我们只要在项⽬中添加⼀个.l⽂件,然后添加⼀个Runner,即可进⾏持续集成。
Pipeline
⼀次 Pipeline 其实相当于⼀次构建任务,⾥⾯可以包含很多个流程,如安装依赖、运⾏测试、编译、部署测试服务器、部署⽣产服务器等流程。任何提交或者 Merge Request 的合并都可以触发 Pipeline 构建。
Stages
Stages 表⽰⼀个构建阶段,也就是上⾯提到的⼀个流程。我们可以在⼀次 Pipeline 中定义多个 Stages,这些 Stages 会有以下特点:所有 Stages 会按照顺序运⾏,即当⼀个 Stage 完成后,下⼀个 Stage 才会开始
只有当所有 Stages 完成后,该构建任务 (Pipeline) 才会成功
如果任何⼀个 Stage 失败,那么后⾯的 Stages 不会执⾏,该构建任务 (Pipeline) 失败tusi8
maine
Jobs
Jobs 表⽰构建⼯作,表⽰某个 Stage ⾥⾯执⾏的⼯作。我们可以在 Stages ⾥⾯定义多个 Jobs,这些 Jobs 会有以下特点:相同 Stage 中的 Jobs 会并⾏执⾏
相同 Stage 中的 Jobs 都执⾏成功时,该 Stage 才会成功
如果任何⼀个 Job 失败,那么该 Stage 失败,即该构建任务 (Pipeline) 失败
job分组
可以把job分组,通过 以下⽅式,job名称为build ruby,有3步。
build ruby 1/3:
stage: build
script:
- echo "ruby1"
build ruby 2/3:
stage: build
script:
- echo "ruby2"
build ruby 3/3:
stage: build
script:
- echo "ruby3"
variables
⾃定义变量
⾃定义变量可以通过以下语句定义:
variables:
TEST:"HELLO WORLD"
预定义变量
There are also .
Variable GitLab Runner Description
CHAT_CHANNEL10.6all The Source chat channel that triggered the command. CHAT_INPUT10.6all The additional arguments pasd with the command.
CI all0.4Available for all jobs executed in CI/CD. true when available. CI_API_V4_URL11.7all The GitLab API v4 root URL.
CI_BUILDS_DIR all11.10The top-level directory where builds are executed.
CI_COMMIT_BEFORE_SHA11.2all The previous latest commit prent on a branch. Is always 0000
000000000000000000000000000000000000 in pipelines for merge requests.
CI_COMMIT_BRANCH12.60.5The commit branch name. Available in branch pipelines,
ky是什么意思
including pipelines for the default branch. Not available in merge request pipelines or tag pipelines.
CI_COMMIT_DESCRIPTION10.8all The description of the commit. If the title is shorter than 100 characters, the message without the first line.
CI_COMMIT_MESSAGE10.8all提交message。
CI_COMMIT_REF_NAME9.0all branch or tag名称
CI_COMMIT_REF_PROTECTED11.11all true if the job is running for a protected reference.
CI_COMMIT_REF_SLUG9.0all CI_COMMIT_REF_NAME in lowerca, shortened to 63 bytes, and with everything except 0-9 and a-z replaced with -. No leading / trailing -. U in URLs, host names and domain names.
CI_COMMIT_SHA9.0all提交version
CI_COMMIT_SHORT_SHA11.7all CI_COMMIT_SHA 前8字符
CI_COMMIT_TAG9.00.5The commit tag name. Available only in pipelines for tags. CI_COMMIT_TIMESTAMP13.4all The timestamp of the commit in the ISO 8601 format.
CI_COMMIT_TITLE10.8all The title of the commit. The full first line of the message. CI_CONCURRENT_ID all11.10The unique ID of build execution in a single executor.
CI_CONCURRENT_PROJECT_ID all11.10The unique ID of build execution in a single executor and project.
CI_CONFIG_PATH9.40.5The path to the CI/CD configuration file. Defaults to .l.
CI_DEBUG_TRACE all 1.7true if is enabled.
CI_DEFAULT_BRANCH12.4all The name of the project’s default branch.
CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX13.7all The image prefix for pulling images through the Dependency Proxy.
CI_DEPENDENCY_PROXY_PASSWORD13.7all The password to pull images through the Dependency Proxy.
CI_DEPENDENCY_PROXY_SERVER13.7all The rver for logging in to the Dependency Proxy. This is equivalent to $CI_SERVER_HOST:$CI_SERVER_PORT.
CI_DEPENDENCY_PROXY_USER13.7all The urname to pull images through the Dependency Proxy. CI_DEPLOY_FREEZE13.2all Only available if the pipeline runs during a . true when available. CI_DEPLOY_PASSWORD10.8all The authentication password of the , if the project has one.
CI_DEPLOY_USER10.8all The authentication urname of the , if the project has one.
CI_DISPOSABLE_ENVIRONMENT all10.1Only available if the job is executed in a disposable environment (something that is created only for this job and dispod
reality是什么意思
of/destroyed after the execution - all executors except shell and ssh). true when available.
CI_ENVIRONMENT_NAME8.15all The name of the environment for this job. Available if is t.
CI_ENVIRONMENT_SLUG8.15all The simplified version of the environment name, suitable for inclusion in DNS, URLs, Kubernetes labels, and so on. Available if is t.
CI_ENVIRONMENT_URL9.3all The URL of the environment for this job. Available if is t.
CI_HAS_OPEN_REQUIREMENTS13.1all Only available if the pipeline’s project has an open . true when available.
CI_JOB_ID9.0all job id
CI_JOB_IMAGE12.912.9运⾏job的容器的image
CI_JOB_JWT12.10all A RS256 JSON web token to authenticate with third party systems that support JWT authentication, for example .
CI_JOB_MANUAL8.12all job是否是⼈⼯执⾏的
CI_JOB_NAME8.12all job名称
brokenarrowCI_JOB_STAGE9.00.5The name of the job’s stage.
CI_JOB_STATUS all13.5The status of the job as each runner stage is executed. U with . Can be success, failed, or canceled.
CI_JOB_TOKEN9.0 1.2A token to authenticate with . The token is valid as long as the job is running.
CI_JOB_URL11.10.5The job details URL.
CI_JOB_STARTED_AT13.10all The UTC datetime when a job started, in format.
CI_KUBERNETES_ACTIVE13.0all Only available if the pipeline has a Kubernetes cluster available for deployments. true when available.
CI_NODE_INDEX11.5all The index of the job in the job t. Only available if the job us .
CI_NODE_TOTAL11.5all The total number of instances of this job running in parallel. Set to 1 if the job does not u .
CI_OPEN_MERGE_REQUESTS13.8all A comma-parated list of up to four merge requests that u the current branch and project as the merge request source. Only available in branch and merge
request pipelines if the branch has an associated merge request. For example, gitlab-org/gitlab!333,gitlab-org/gitlab-foss!11.
CI_PAGES_DOMAIN11.8all The configured domain that hosts GitLab Pages.
加油的英语怎么说
CI_PAGES_URL11.8all The URL for a GitLab Pages site. Always a subdomain of CI_PAGES_DOMAIN.
Variable GitLab Runner Description
CI_PIPELINE_ID8.10all流⽔线ID,gitlab实例内唯⼀CI_PIPELINE_IID11.0all流⽔线ID,项⽬内唯⼀
CI_PIPELINE_SOURCE10.0all How the pipeline was triggered. Can be push, web, schedule, api, external, chat, webide, merge_request_event,
external_pull_request_event, parent_pipeline, .
CI_PIPELINE_TRIGGERED all all true if the job was .英文网名大全
CI_PIPELINE_URL11.10.5The URL for the pipeline details.
CI_PIPELINE_CREATED_AT13.10all The UTC datetime when the pipeline was created, in format.
CI_PROJECT_CONFIG_PATH13.8all (Deprecated) The CI configuration path for the project. in GitLab 13.10. for GitLab 14.0.
CI_PROJECT_DIR all all The full path the repository is cloned to, and where the jobeverytime
runs from. If the GitLab Runner builds_dir parameter is t, this variable is t relative to the value of builds_dir. For more information, e the .
CI_PROJECT_ID all all The ID of the current project. This ID is unique across all projects on the GitLab instance.
CI_PROJECT_NAME8.100.5The name of the directory for the project. For example if the project URL /group-name/project-1,
CI_PROJECT_NAME is project-1.
CI_PROJECT_NAMESPACE8.100.5The project namespace (urname or group name) of the job.
CI_PROJECT_PATH_SLUG9.3all $CI_PROJECT_PATH in lowerca with characters that are not a-z or 0-9 replaced with -. U in URLs and domain names.
CI_PROJECT_PATH8.100.5The project namespace with the project name included.
CI_PROJECT_REPOSITORY_LANGUAGES12.3all A comma-parated, lowerca list of the languages ud in the repository. For example ruby,javascript,html,css.
CI_PROJECT_ROOT_NAMESPACE13.20.5The root project namespace (urname or group name) of the job. For example, if CI_PROJECT_NAMESPACE is root-
truly madly deeplygroup/child-group/grandchild-group,
CI_PROJECT_ROOT_NAMESPACE is root-group.
CI_PROJECT_TITLE12.4all The human-readable project name as displayed in the GitLab web interface.
CI_PROJECT_URL8.100.5The HTTP(S) address of the project.
CI_PROJECT_VISIBILITY10.3all The project visibility. Can be internal, private, or public.
CI_REGISTRY_IMAGE8.100.5The address of the project’s Container Registry. Only available if the Container Registry is enabled for the project.
CI_REGISTRY_PASSWORD9.0all The password to push containers to the project’s GitLab Container Registry. Only available if the Container Registry is enabled for the project.
CI_REGISTRY_USER9.0all The urname to push containers to the project’s GitLab Container Registry. Only available if the Container Registry is enabled for the project.
白马王子的英文
CI_REGISTRY8.100.5The address of the GitLab Container Registry. Only available if the Container Registry is enabled for the project. This variable includes a :port value if one is specified in the registry configuration.
CI_REPOSITORY_URL9.0all The URL to clone the Git repository. CI_RUNNER_DESCRIPTION8.100.5The description of the runner. Variable GitLab Runner Description
CI_RUNNER_EXECUTABLE_ARCH all10.6The OS/architecture of the GitLab Runner executable. Might not be the same as the environment of the executor.
CI_RUNNER_ID8.100.5The unique ID of the runner being ud. CI_RUNNER_REVISION all10.6The revision of the runner running the job.
CI_RUNNER_SHORT_TOKEN all12.3First eight characters of the runner’s token ud to authenticate new job requests. Ud as the runner’s unique ID.
CI_RUNNER_TAGS8.100.5 A comma-parated list of the runner tags.
CI_RUNNER_VERSION all10.6The version of the GitLab Runner running the job.
CI_SERVER_HOST12.1all The host of the GitLab instance URL, without protocol or port. For
CI_SERVER_NAME all all The name of CI/CD rver that coordinates jobs.
CI_SERVER_PORT12.8all The port of the GitLab instance URL, without host or protocol. For example 8080.
CI_SERVER_PROTOCOL12.8all The protocol of the GitLab instance URL, without host or port. For example https.
CI_SERVER_REVISION all all GitLab revision that schedules jobs.
CI_SERVER_URL12.7all The ba URL of the GitLab instance, including protocol and port. For :8080.
CI_SERVER_VERSION_MAJOR11.4all The major version of the GitLab instance. For example, if the GitLab version is 13.6.1, the CI_SERVER_VERSION_MAJOR is 13.
CI_SERVER_VERSION_MINOR11.4all The minor version of the GitLab instance. For example, if the GitLab version is 13.6.1, the CI_SERVER_VERSION_MINOR is 6.
CI_SERVER_VERSION_PATCH11.4all The patch version of the GitLab instance. For example, if the GitLab version is 13.6.1, the CI_SERVER_VERSION_PATCH is 1.
CI_SERVER_VERSION all all The full version of the GitLab instance.
CI_SERVER all all Available for all jobs executed in CI/CD. yes when available.
CI_SHARED_ENVIRONMENT all10.1Only available if the job is executed in a shared environment (something that is persisted across CI/CD invocations, like the shell or ssh executor). true when available.
GITLAB_CI all all Available for all jobs executed in CI/CD. true when available.
GITLAB_FEATURES10.6all The comma-parated list of licend features available for the GitLab instance and licen.
GITLAB_USER_EMAIL8.12all The email of the ur who started the job.
GITLAB_USER_ID8.12all The ID of the ur who started the job.
GITLAB_USER_LOGIN10.0all The urname of the ur who started the job. GITLAB_USER_NAME10.0all The name of the ur who started the job.
TRIGGER_PAYLOAD13.9all The webhook payload. Only available when a pipeline is . Variable GitLab Runner Description
使⽤变量
Shell Usage