美文网首页
gitlab 安装和基本使用

gitlab 安装和基本使用

作者: 华阳_3bcf | 来源:发表于2020-01-09 16:06 被阅读0次

gitlab 安装和基本使用

这篇文章是站在运维人员的立场,测试最核心的功能Central Git Repo 和 GitLab CI。

1. 安装GitLab

参考官方文档 install on ubuntu18

1.1 安装依赖包

sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates

sudo apt-get install -y postfix

邮件配置时候选择Internet即可

1.2 下载和安装 GitLab

$ curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5933    0  5933    0     0   7416      0 --:--:-- --:--:-- --:--:--  7406
Detected operating system as Ubuntu/bionic.
Checking for curl...
Detected curl...
Checking for gpg...
Detected gpg...
Running apt-get update... done.
Installing apt-transport-https... done.
Installing /etc/apt/sources.list.d/gitlab_gitlab-ce.list...done.
Importing packagecloud gpg key... done.
Running apt-get update... done.

The repository is setup! You can now install packages.

Next, install the GitLab package. Change https://roy-gitlab.eastasia.cloudapp.azure.com to the URL at which you want to access your GitLab instance.

sudo EXTERNAL_URL="http://roy-gitlab.eastasia.cloudapp.azure.com" apt-get install gitlab-ce

1.3 网页登陆

第一次登陆,要重设密码,然后用 root 账户登陆进去。

img

2. 创建Project,设置 ssh key

img

3. clone repo

在客户端执行

$ git clone git@roy-gitlabce.eastasia.cloudapp.azure.com:root/demo.git

现在就可以修改代码并push 代码了。

4. 安装runner

这是给GitLab CI,做准备的。

在新的一台VM操作(以ubuntu为例)。

runner 相当于 Jenkins 中的 slave,job 就在这里运行。

https://docs.gitlab.com/runner/install/linux-repository.html

Add GitLab’s official repository:

curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash

Install the latest version of GitLab Runner

sudo apt-get install gitlab-runner

Register the Runner

公用的runner,找 token 去 admin/runners page

Project runner,去 Settings > CI/CD 获取token

$ sudo gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=17752 revision=ac8e767a version=12.6.0
Running in system-mode.

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://roy-gitlabce.eastasia.cloudapp.azure.com/
Please enter the gitlab-ci token for this runner:
GgJxBX1KPeuCK7-8ut6-
Please enter the gitlab-ci description for this runner:
[roy-runner]: my-runner
Please enter the gitlab-ci tags for this runner (comma separated):
my-tag
Registering runner... succeeded                     runner=GgJxBX1K
Please enter the executor: parallels, shell, ssh, virtualbox, docker, docker-ssh, docker-ssh+machine, kubernetes, custom, docker+machine:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

5. CI/CD 测试

参考官方文档:https://docs.gitlab.com/ee/ci/

在demo repo 根目录创建文件 .gitlab-ci.yml ,内容如下

# 定义 stages(阶段,会依次执行)
stages:
  - install_deps
  - build_prod
  - deploy_prod

# 安装构建依赖
install_deps_job:
  stage: install_deps
  # 在哪个分支才会执行脚本
  only:
    # - dev
    # - release
    - master
  script:
    - echo 'It is pre-install phase'
  tags:
    - my-tag

build_prod_job:
  stage: build_prod
  only:
    - master
  script:
    - echo 'It is build phase'
  tags:
    - my-tag

deploy_prod_job:
  stage: deploy_prod
  only:
    - master
  script:
    - echo 'It is deploy phase'
  tags:
    - my-tag

.gitlab-ci.yml的具体写法,以及关键字含义见: 链接

把它push 到GitLab

git add .gitlab-ci.yml
git commit -m "Add .gitlab-ci.yml"
git push origin master

GitLab 会自动触发CI/CD

image-20191223171325659.png

可以看到Pipeline里面 3个job build 成功,可以点击进去,看详细的日志。

相关文章

  • gitlab 安装和基本使用

    gitlab 安装和基本使用 这篇文章是站在运维人员的立场,测试最核心的功能Central Git Repo 和 ...

  • Git使用

    gitlab 一、git基本使用 安装git:sudoaptinstallgit 设置自己的用户名和邮箱 gith...

  • git的基本使用

    gitlab 一、git基本使用 安装git: sudo apt install git 设置自己的用户名和邮箱...

  • Gitlab 备份、恢复

    vim /etc/gitlab/gitlab.rb 使用Gitlab一键安装包安装Gitlab非常简单, 同样的备...

  • docker 安装 gitlab 中文汉化

    gitlab安装 本文只讲述如何使用docker安装gitlab,包括中文和英文两种版本,大家自行进行选择进行安装...

  • GitLab 迁移

    Gitlab 修改普通用户密码 Gitlab 创建备份 使用Gitlab一键安装包安装Gitlab非常简单, 同样...

  • jenkins自动化环境搭建

    安装gitlab 注:本地的IP地址为192.168.1.10 使用docker安装gitlab docker p...

  • Linux(centos7)下gitlab使用自己安装的ngin

    一、使用oneinStack安装lamp环境 二、安装gitlab 三、修改gitlab配置 四、配置nginx ...

  • gitlab 灾备

    Gitlab创建备份 使用Gitlab一键安装包安装Gitlab非常简单,同样的备份恢复与迁移也非常简单.使用一条...

  • docker下gitlab安装配置使用(完整版)

    docker 安装gitlab以及使用 一、安装及配置 1.gitlab镜像拉取 2.运行gitlab镜像 运行成...

网友评论

      本文标题:gitlab 安装和基本使用

      本文链接:https://www.haomeiwen.com/subject/irgyactx.html