
- 亚搏体育appGitLab教程
- 亚搏体育appGitLab - 主页
- 亚搏体育appGitLab基础知识
- 亚搏体育appGitLab - 简介
- 亚搏体育appGitLab-安装
- GitLab - Git 命令
- GitLab - SSH 密钥设置
- GitLab - 创建项目
- GitLab - 分叉一个项目
- GitLab - 创建分支
- GitLab - 添加文件
- GitLab - 变基操作
- GitLab - 压缩提交
- 亚搏体育appGitLab用户和组
- GitLab - 添加用户
- GitLab - 创建组
- GitLab - 删除用户
- GitLab - 用户权限
- 亚搏体育appGitLab问题跟踪器
- GitLab - 创建问题
- GitLab - 合并请求
- GitLab - 引用问题
- 亚搏体育appGitLab - 里程碑
- GitLab - 维基页面
- 亚搏体育appGitLab实例管理
- GitLab - 创建备份
- GitLab - 恢复备份
- GitLab - 导入存储库
GitLab CI - CI 的高级用法
环境和部署
环境用于测试、构建和部署 CI(持续集成)作业,并通过 GitLab 控制软件的持续部署。GitLab CI 能够跟踪您的项目部署,您也将了解服务器上正在部署的内容。
环境的名称可以使用环境:名称字符串来定义,并包含以下内容 -
- 字母
- 数字
- 空间
- -
- _
- /
- $
- {
- }
将 SSH 密钥与 GitLab CI/CD 结合使用
您可以设置 SSH(Secure Shell 或 Secure Socket Shell)密钥以在计算机和 GitLab 之间提供可靠的连接。SSH 密钥可以在以下情况下与 GitLab CI/CD 一起使用:
- 您需要检查内部子模块。
- 您需要使用包管理器下载私有包。
- 您需要将应用程序安装到您自己的服务器上。
- 您从构建环境向远程服务器执行 SSH 命令。
- 您需要将文件从构建环境 rsync 到远程服务器。
GitLab SSH 密钥设置章节中解释了SSH 密钥设置。
文物
工件用于在成功后将文件和目录列表附加到作业。工件包含以下类型 -
- artifacts:name - 该指令用于指定创建的工件存档的名称。它为创建的工件存档提供唯一的名称,这在您从 GitLab 下载存档时很有帮助。
- artifacts:when - 该指令用于在作业失败时上传工件。它包含以下值:
- on_success - 用于在作业成功时上传工件。
- on_failure - 用于在作业失败时上传工件。
- 总是- 它用于上传工件,无论作业状态如何。
- artifacts:expire_in - 它定义工件在过期并因此被删除之前应存活多长时间,因为它们上传并存储在 GitLab 上
触发管道
触发器可以强制通过 API 调用重建特定分支或标签,并且具有旧标签的触发器将有权访问当前项目。
可以按照以下步骤添加新触发器 -
第 1 步- 登录您的 GitLab 帐户并转到您的项目 -

步骤 2 - 单击“设置”选项卡下的CI/CD选项,然后展开“管道触发器”选项 -

输入触发器的描述,然后单击“添加触发器”按钮。
步骤 3 - 接下来,创建触发器后将显示成功消息 -

步骤 4 - 现在转到“设置”选项卡下的CI/CD选项,然后展开“管道触发器”选项。您将看到新创建的触发器以及令牌,如下图所示 -

管道时间表
您可以使用管道计划以特定时间间隔运行管道。要创建管道计划,请使用以下步骤 -
第 1 步- 登录您的 GitLab 帐户并转到您的项目 -
步骤 2 - 单击CI/CD选项卡下的Schedules选项,然后单击New Schedule按钮 -

步骤 3 - 接下来,它将打开“调度新管道”屏幕,填写字段并单击“保存管道计划”按钮 -

步骤 4 - 现在,您将看到计划运行的管道 -

将 GitLab 与 Kubernetes 集群连接
Kubernetes 集群可用于以简单的方法审查和部署应用程序、运行管道等。您可以通过将您的 GitLab 帐户与 Google Kubernetes Engine (GKE) 关联来为您的项目创建新集群。
可以按照以下步骤创建新的 Kubernetes 集群 -
第 1 步- 登录您的 GitLab 帐户并转到您的项目 -

步骤 2 - 单击CI/CD选项卡下的Kubernetes选项-

步骤 3 - 接下来,单击“添加 Kubernetes 集群”按钮 -

步骤 4 - 单击“在 GKE 上创建”按钮以在 Google Kubernetes Engine 上创建新的 Kubernetes 集群 -

步骤 5 - 如果您有 Google 帐户,请使用该帐户登录以输入 Kubernetes 集群的详细信息,或者创建一个新的 Google 帐户 -

步骤 6 - 现在在 Kubernetes 集群的字段中输入值 -

步骤 7 - 在字段中添加值之前,您需要在 Google Cloud Platform 控制台中创建的项目 ID 来托管 Kubernetes 集群。要创建 ID,请单击上图中突出显示的“查看您的项目”链接。它将打开下面的屏幕,然后单击“我的项目”菜单,然后单击加号(+)图标来创建一个新项目 -

步骤 8 - 现在输入项目名称并单击“创建”按钮 -

步骤 9 - 您将获得将托管 Kubernetes 集群的项目的 ID -

步骤 10 - 在 Kubernetes 集群字段中输入值以及 Google Cloud Platform 项目 ID,然后单击“创建 Kubernetes 集群”按钮 -
