GVKun编程网logo

gitlab 中的 Git 克隆在 linux 上失败,而在 Windows git bash 中工作(git从gitlab上克隆项目)

1

此处将为大家介绍关于gitlab中的Git克隆在linux上失败,而在Windowsgitbash中工作的详细内容,并且为您解答有关git从gitlab上克隆项目的相关问题,此外,我们还将为您介绍关于

此处将为大家介绍关于gitlab 中的 Git 克隆在 linux 上失败,而在 Windows git bash 中工作的详细内容,并且为您解答有关git从gitlab上克隆项目的相关问题,此外,我们还将为您介绍关于22.13-22.17 搭建 git 服务器,安装 gitlab, 使用 gitlab,gitlab 备份与恢复、Anaconda/Git:git branch 命令虽然在 WSL Ubuntu 中工作,但它是无声的、Android Gitlab CI作业在“ PlayStore:设备是否支持Google Play?”上失败、CICD持续集成: .gitlab-ci.yml配置小记(gitlab-ci + gitlab-runner)的有用信息。

本文目录一览:

gitlab 中的 Git 克隆在 linux 上失败,而在 Windows git bash 中工作(git从gitlab上克隆项目)

gitlab 中的 Git 克隆在 linux 上失败,而在 Windows git bash 中工作(git从gitlab上克隆项目)

如何解决gitlab 中的 Git 克隆在 linux 上失败,而在 Windows git bash 中工作

我是 Linux 新手,刚刚安装了 Lubuntu 并遇到了问题 - 当我试图从我公司的 git 克隆我的远程工作仓库时:

$ sudo git clone https://path/to/repo.git

我一直收到错误:

cloning into ''repo''...
fatal: unable to access ''https://path/to/repo.git/'': server certificate verification Failed. CAfile: none CRLfile: none

我知道它提到了证书,但我没有。之前,我在 Windows 上工作,并且能够在没有任何证书的情况下简单地 git clone 这个 repo。

解决方法

此错误表示git客户端无法验证证书链或根的完整性。解决此问题的正确方法是确保来自远程存储库的证书有效,然后添加到客户端系统。

更新公共 CA 列表

我建议的第一件事是简单地更新系统已知的根 CA 列表,如下所示。

# update CA certificates
sudo apt-get install apt-transport-https ca-certificates -y
sudo update-ca-certificates

如果您正在处理一个长期未更新的系统,这可能会有所帮助,但当然不会解决私有证书的问题。

获取证书,直连

如果您将来自远程 git 服务器的证书添加到本地检查的证书列表中,则来自 git 客户端的错误将得到解决。这可以通过使用 openssl 从远程主机拉取证书来完成:

openssl s_client -showcerts -servername git.mycompany.com -connect git.mycompany.com:443 </dev/null 2>/dev/null | sed -n -e ''/BEGIN\\ CERTIFICATE/,/END\\ CERTIFICATE/ p''  > git-mycompany-com.pem

这将获取“https://git.mycompany.com”使用的证书,并将内容复制到名为“git-mycompany-com.pem”的本地文件中。

获取证书,网络代理

如果该主机只能通过像 Squid 这样的 Web 代理访问 git 服务器,则如果您使用的是 OpenSSL 1.1.0 及更高版本,则 openssl 将只能利用 squid 代理。但是,如果您使用的是旧版本的 OpenSSL,则需要通过使用 socat 之类的东西在本地绑定到端口 4443,并通过 squid 代理流量并到达最终目的地来解决此限制。

# install socat
sudo apt-get install socat -y

# listen locally on 4443,send traffic through squid "squidhost"
socat TCP4-LISTEN:4443,reuseaddr,fork PROXY:squidhost:git.mycompany.com:443,proxyport=3128

然后在另一个控制台中,告诉 OpenSSL 从 localhost 的 4443 端口提取证书。

openssl s_client -showcerts -servername git.mycompany.com -connect 127.0.0.1:4443 </dev/null 2>/dev/null | sed -n -e ''/BEGIN\\ CERTIFICATE/,/END\\ CERTIFICATE/ p'' > git-mycompany-com.pem

将证书添加到本地证书列表

无论是通过代理还是直接连接,您现在都在名为“git-mycompany-com.pem”的文件中拥有远程证书列表。此文件将包含证书、其中间链和根 CA 证书。 下一步是让 git 客户端在连接到 git 服务器时考虑这一点。这可以通过将证书添加到原始错误中提到的文件中来完成,在这种情况下,对所有用户全局进行更改,或者可以将其添加到单个用户的 git 配置中。

** 全局添加 **

cat git-mycompany-com.pem | sudo tee -a /etc/ssl/certs/ca-certificates.crt

** 单用户添加**

git config --global http."https://git.mycompany.com/".sslCAInfo ~/git-mycompany-com.pem

默默地将以下几行添加到 ~/.gitconfig

[http "https://git.mycompany.com/"]
        sslCAInfo = /home/user/git-mycompany-com.pem

避免变通方法

避免跳过 SSL 认证验证的解决方法。仅使用它们来快速测试证书是根本问题,然后使用上述部分来解决问题。

git config --global http.sslverify false

export GIT_SSL_NO_VERIFY=true

22.13-22.17 搭建 git 服务器,安装 gitlab, 使用 gitlab,gitlab 备份与恢复

22.13-22.17 搭建 git 服务器,安装 gitlab, 使用 gitlab,gitlab 备份与恢复

OSC 请你来轰趴啦!1028 苏州源创会,一起寻宝 AI 时代

22.13-22.17 搭建 git 服务器,安装 gitlab, 使用 gitlab,gitlab 备份与恢复

转载 weixin_34413357 发布于 2018-09-05 16:31:52 阅读数 1  收藏
展开

22.13 搭建 git 服务器

22.14 22.15 安装 gitlab

22.16 使用 gitlab

22.17 gitlab 备份与恢复

 

22.13 搭建 git 服务器

github 毕竟是公开的,而私有仓库又得花钱买。所以我们可以想办法搭建一个私有的,只自己公司使用的。Gitlab 是个不错的选择。在介绍它之前,先讲述一下命令行的 git 服务器

搭建准备工作

1 找一台服务器,首先要安装 git,

yum install -y git

2 添加 git 用户,并且设置 shell 为 /usr/bin/git-shell, 目的是为了不让 git 用户远程登陆

useradd -s /usr/bin/git-shell git 
cd /home/git

3 创建 authorized_keys 文件,并更改属主、属组和权限,用来存客户端机器上的公钥

mkdir .ssh
touch .ssh/authorized_keys
chown -R git.git .ssh
chmod 600 .ssh/authorized_keys

4 把客户端的公钥,放到服务器的 /root/.ssh/authorized_keys 上,失效免密登录

[root@9F-VM1 ~]# cat .ssh/id_rsa.pub
Nlet2N+TXAQJDOnrRtN42qFoRLAYXO+D8xsYDmwPMLdJymcYBbQJL5jU65/+loL7kuHcTtRSwk46xQXdLFPjN/c2c0I6OofxZAVKgPHGtjd8Y8dkOzYep6S6n7C/jug5PwbQedFoNy16+0JU1lBQa6IxqrWsXdLuM3Gc8Oko4sAvKQgZQRfJh root@9F-VM1
[root@DD-Server-9F ~]# vim !$
vim .ssh/authorized_keys
#9F-VM1
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7TRMjzg1SiLIZg3X3HBVaVzvfCMouDV/d0owu/SLddyHAitEvii3Nq1ElOhuB2hDbVq9fhEH61ZuBVqI+PkcI0KE04p8/KCSzF4dEvUdIYrQAeafxnLd7hl4QofmJbEnP07FQOurFFXItnniGz12mN95cbvijoLPNlet2N+TXA

5 登录验证测试

[root@9F-VM1 ~]# ssh git@192.88.24.200
Last login: Tue Sep  4 16:16:31 2018 from 192.88.29.250
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to 192.88.24.200 closed.

不能直接远程通过登录的,但是能验证到客户端 29.250 的公钥,稍后会再做说明。

 

在服务器创建 git 仓库

6 定好存储 git 仓库的目录,比如 /data/git

 mkdir /data/git
 cd /data/git

7 初始化仓库

[root@DD-Server-9F git]#  git init --bare sample.git

 

# 会创建一个裸仓库,裸仓库没有工作区,因为服务器上的 Git 仓库纯粹是为了共享,所以不让用户直接登录到服务器上去改工作区,并且服务器上的 Git 仓库通常都以.git 结尾

chown -R git.git sample.git

以上操作是在 git 服务器上做的,平时 git 服务器是不需要开发人员登录修改代码的,它仅仅是充当着一个服务器的角色,就像 github 一样,平时操作都是在我们自己的 pc 上做的

 

8 客户端使用仓库

 首先要把客户端上的公钥放到 git 服务器上 /home/git/.ssh/authorized_keys 文件里

 在客户端上(自己 pc)克隆远程仓库

 

执行命令:

 git clone git@ip:/data/git/sample.git
[root@9F-VM1 git]# cd /data/git
[root@9F-VM1 git]# git clone git@192.88.24.200:/data/git/sample.git
正克隆到 ''sample''...
warning: 您似乎克隆了一个空版本库。
[root@9F-VM1 git]# cd sample/
[root@9F-VM1 sample]# ls -la
总用量 0
drwxr-xr-x 3 root root  18 9   4 16:41 .
drwxr-xr-x 9 root root 131 9   4 16:41 ..
drwxr-xr-x 7 root root 119 9   4 16:41 .git

此时就可以在当前目录下生成一个 sample 的目录,这个就是我们克隆的远程仓库了。进入到这里面,可以开发一些代码,然后 push 到远程。

 

9 测试

添加文件实现远程仓库功能

[root@9F-VM1 sample]# touch 1.txt && echo -e "111\n222\n333" >> 1.txt
[root@9F-VM1 sample]# cat 1.txt
111
222
333
[root@9F-VM1 sample]# git add 1.txt
[root@9F-VM1 sample]# git commit -m "add the first file"
[master(根提交) e46c02a] add the first file
 1 file changed, 3 insertions(+)
 create mode 100644 1.txt
[root@9F-VM1 sample]# git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 219 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.88.24.200:/data/git/sample.git
 * [new branch]      master -> master

9.1 在别的目录克隆远程仓库,查看协同效果是否实现

[root@9F-VM1 git]# cd /data/git
[root@9F-VM1 git]# mkdir sample-t
[root@9F-VM1 git]# cd sample-t/
[root@9F-VM1 sample-t]# git clone git@192.88.24.200:/data/git/sample.git
正克隆到 ''sample''...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
接收对象中: 100% (3/3), done.
[root@9F-VM1 sample-t]# ls
sample
[root@9F-VM1 sample-t]# cd sample/
[root@9F-VM1 sample]# ls
1.txt
[root@9F-VM1 sample]# vim 2.txt
[root@9F-VM1 sample]# echo "222" > 2.txt
[root@9F-VM1 sample]# ls
1.txt  2.txt
[root@9F-VM1 sample]# git add 2.txt
[root@9F-VM1 sample]# git commit -m "add 2.txt"
[master 0f7b313add 2.txt
 1 file changed, 1 insertion(+)
 create mode 100644 2.txt
[root@9F-VM1 sample]# git push
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 261 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.88.24.200:/data/git/sample.git
   e46c02a..0f7b313  master -> master

切换原来开始的仓库目录

[root@9F-VM1 sample]# cd -
/data/git/sample
[root@9F-VM1 sample]# ls
1.txt
[root@9F-VM1 sample]# git pull
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
来自 192.88.24.200:/data/git/sample
   e46c02a..0f7b313  master     -> origin/master
更新 e46c02a..0f7b313
Fast-forward
 2.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 2.txt
[root@9F-VM1 sample]# ls
1.txt  2.txt

协同实现,远程仓库项目搭建完成

 

 

22.14 安装 gitlab (上)

 

安装方法一:

 gitlab 官网 https://about.gitlab.com/gitlab-com/

 官方安装文档 https://about.gitlab.com/installation/?version=ce#centos-7 (ce/ee)

 要求服务器内存不少于 2g

方法二:本地 yum 源安装

vim /etc/yum.repos.d/gitlab.repo //加入如下内容
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
yum install -y gitlab-ce
gitlab-ctl reconfigure

 

22.15 安装 gitlab (下)

执行命令自动加载配置

 gitlab-ctl reconfigure

 

如果系统自带 nginx,先把它停掉,因为 gitlab 也自带了一个 nginx,以免发生冲突

/etc/init.d/nginx stop
chkconfig nginx off
netstat -lnpt  //查看监听端口
gitlab-ctl 
#后面带的执行命令(停止,开始,重启,状态)
gitlab-ctl stop/restart/start/status

访问 gitlab 服务器 ip:192.88.24.200

第一次登录需要创建新的密码

改完密码后需要登录

默认账户:root

密码:新的密码

blob.png

 

22.16 使用 gitlab

 

gitlab 常用命令  https://www.cnyunwei.cc/archives/1204 

1 使用 gitlab 自带的 nginx 配置代理

路径:

/var/opt/gitlab/nginx/conf/nginx.conf

#主配置文件

/var/opt/gitlab/nginx/conf/gitlab-http.conf

#gitlab 相关的 web 配置文件,修改相关 gitlab web 可以在这里修改

 

2 创建新的组 group

blob.png

blob.png

3 创建新的项目 project

blob.png

4 在 gitlab 添加 SSH Key

User Settings-->SSH key--> 把公钥复制进去

blob.png

5 添加组

管理员区域 添加用户,组,项目

blob.png

 

6 添加用户

密码获取方法一:新的用户密码会使用链接方式将密码发送通知给邮件地址来获取

blob.png

密码获取方法二:选中用户 -->Edit 下直接编辑定义密码

blob.png

 

7 新用户登录

创建项目 project

 

22.17 gitlab 备份与恢复

 

1 gitlab 备份  

gitlab-rake gitlab:backup:create
[root@DD-Server-9F ~]# gitlab-rake gitlab:backup:create
Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
 * g1/p1 ... [SKIPPED]
[SKIPPED] Wiki
 * kevin/kp01 ... [SKIPPED]
[SKIPPED] Wiki
done
Dumping uploads ...
done
Dumping builds ...
done
Dumping artifacts ...
done
Dumping pages ...
done
Dumping lfs objects ...
done
Dumping container registry images ...
[DISABLED]
Creating backup archive: 1536129054_2018_09_05_11.2.3_gitlab_backup.tar ... done
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... skipping

备份目录在 /var/opt/gitlab/backups

[root@DD-Server-9F ~]# ls /var/opt/gitlab/backups/
1536129054_2018_09_05_11.2.3_gitlab_backup.tar

2 gitlab 恢复

gitlab 恢复  先停服务 gitlab-ctl stop unicorn ; gitlab-ctl stop sidekiq

[root@DD-Server-9F ~]# gitlab-ctl stop unicorn ; gitlab-ctl stop sidekiq
ok: down: unicorn: 1s, normally up
ok: down: sidekiq: 0s, normally up

停掉服务后,继续恢复

gitlab-rake gitlab:backup:restore BACKUP=xxxxx (这里是一个编号,即备份文件的前缀,时间戳_日期_版本号)

[root@DD-Server-9F ~]# gitlab-rake gitlab:backup:restore BACKUP=1536129054_2018_09_05_11.2.3

Anaconda/Git:git branch 命令虽然在 WSL Ubuntu 中工作,但它是无声的

Anaconda/Git:git branch 命令虽然在 WSL Ubuntu 中工作,但它是无声的

如何解决Anaconda/Git:git branch 命令虽然在 WSL Ubuntu 中工作,但它是无声的

每次我尝试运行“git branch”命令(git branch -vv 或 git branch -a)的任何变体时,它们都不起作用。我收到一个空行,如图 1 所示。

常见的建议是对 repo 进行提交。我已经这样做了,但仍然无法正常工作。

另一个常见的建议是:“git remote prune origin”。这也无济于事。

然后我使用:“conda install -c anaconda git”重新安装了 git。没有变化。另外,我安装了 GIT GUI,如果这表明有任何意义(我怀疑它确实如此)。

如果感兴趣的话,我的 Anaconda 提示在每次运行“git branch”时都会闪烁,但在我运行其他命令时不会(几乎就像是重新输出提示什么的,idk 真的知道)。

让我向你展示我的 git 输出:

Fig. 1: Anaconda Prompt

Anaconda 对我来说就像一个黑匣子。我对它不是很熟悉,所以任何帮助将不胜感激。

解决方法

这个问题的答案可以在这个 Stack Overflow 线程中找到:Link。谢谢博士。

Android Gitlab CI作业在“ PlayStore:设备是否支持Google Play?”上失败

Android Gitlab CI作业在“ PlayStore:设备是否支持Google Play?”上失败

如何解决Android Gitlab CI作业在“ PlayStore:设备是否支持Google Play?”上失败

您好,目前我正在Gitlab中为我的Android项目实现CI,其他测试脚本运行正常,但是在进行仪器测试时,我遇到了PlayStore: Does the device supports Google Play?错误,我是否缺少某些命令?

错误日志

$ echo y | android-sdk-linux/tools/bin/avdmanager create avd -f -n testAVD -k "system-images;android-${ANDROID_COMPILE_SDK};google_apis;x86"
Loading local repository...                                                     
[=========                              ] 25% Loading local repository...       
[=========                              ] 25% Fetch remote repository...        
[=========                              ] 25% Fetch remote repository...        
[=========                              ] 25% Fetch remote repository...        
[=======================================] 100% Fetch remote repository...       
Auto-selecting single ABI x86
Do you wish to create a custom hardware profile? [no] 
PlayStore: Does the device supports Google Play?
PlayStore.enabled [no]:String index out of range: -1
ERROR: Job Failed: exit code 1

.gitlab-ci.yml

image: openjdk:8-jdk

variables:
  ANDROID_COMPILE_SDK: "29"
  ANDROID_BUILD_TOOLS: "29.0.3"
  ANDROID_SDK_TOOLS: "4333796"
  CMAKE: "3.10.2.4988404"

before_script:
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1

  - wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
  - unzip -d android-sdk-linux android-sdk.zip
  - echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
  - echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
  - echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
  - echo y | android-sdk-linux/tools/bin/sdkmanager "ndk-bundle" >/dev/null
  - echo y | android-sdk-linux/tools/bin/sdkmanager "cmake;${CMAKE}" >/dev/null

  - export ANDROID_HOME=$PWD/android-sdk-linux/
  - export CMAKE_HOME=$PWD/android-sdk-linux/cmake/${CMAKE}/bin/
  - export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/:$CMAKE_HOME

  - chmod +x ./gradlew
  # temporarily disable checking for EPIPE error and use yes to accept all licenses
  - set +o pipefail
  - yes | android-sdk-linux/tools/bin/sdkmanager --licenses
  - set -o pipefail

stages:
  - build
  - test

#lintDebug:
#  stage: build
#  script:
#    - ./gradlew -Pci --console=plain :app:lintLeakCanaryDebug -PbuildDir=lint

assembleDebug:
  stage: build
  script:
    - ./gradlew assembleDebug
  artifacts:
    paths:
      - app/build/outputs/

unitTest:
  stage: test
  script:
    - ./gradlew -Pci --console=plain :app:testLeakCanaryDebugUnitTest # change to testLeakCanaryDebugUnitTest (under verification)

instrumentationTest:
  stage: test
  script:
    - echo y | android-sdk-linux/tools/bin/sdkmanager  "emulator" >/dev/null
    - echo y | android-sdk-linux/tools/bin/sdkmanager "system-images;android-${ANDROID_COMPILE_SDK};google_apis;x86"
    - echo y | android-sdk-linux/tools/bin/avdmanager create avd -f -n testAVD -k "system-images;android-${ANDROID_COMPILE_SDK};google_apis;x86"
    - android-sdk-linux/emulator/emulator -avd testAVD -no-audio -no-window &
    - ./gradlew connectedAndroidTest

PlayStore.enabled [no]:字符串索引超出范围是什么:-1是什么意思?

更新: 我想出了如何在创建avd时仅绕过echo n

- echo n | android-sdk-linux/tools/bin/avdmanager create avd -f -n testAVD -k "system-images;android-${ANDROID_COMPILE_SDK};google_apis;x86_64"

基本上,回显n是在创建avd时对问题Do you wish to create a custom hardware profile?的否定回答。然后,它将跳过所有avd问题,并继续创建默认avd。

CICD持续集成: .gitlab-ci.yml配置小记(gitlab-ci + gitlab-runner)

CICD持续集成: .gitlab-ci.yml配置小记(gitlab-ci + gitlab-runner)

参考博文:基于gitlab-ci的CICD

概念

GitLab-CI
GitLab自带的持续集成系统,负责.gitlab-ci.yml脚本解析。

GitLab-Runner
脚本执行的承载者。GitLab-CI解析.gitlab-ci.yml文件后,根据里面配置的规则,分配到各个Runner来运行相应的脚本script。

.gitlab-ci.yml
位于git项目根目录,记录了一系列的阶段和执行规则。

Pipeline
一次 Pipeline 其实相当于一次构建任务,里面可以包含多个流程,如安装依赖、运行测试、编译、部署测试服务器、部署生产服务器等流程。

Stages
构建阶段(上述所说的流程)。一次 Pipeline 中可以定义多个 Stages,所有 Stages 会按顺序运行,前一个 Stage 完成后,下一个才会开始。只有当所有 Stages 完成后,该构建任务 (Pipeline) 才会成功。任何一个 Stage 失败,后面的 Stages 都不会执行,该构建任务失败。

Jobs
构建工作,某个 Stage 里面执行的具体内容。我们可以在 Stages 里面定义多个 Jobs,相同 Stage 中的 Jobs 会并行执行。相同 Stage 中的 Jobs 都执行成功时,该 Stage 才会成功,如果任何一个 Job 失败,那么该 Stage 失败,即该构建任务 (Pipeline) 失败。

流程

1575862161805498.png

安装部署

添加gitlab官方库

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

安装最新版本的gitlab-runner

yum -y install gitlab-runner

启动服务

gitlab-runner list 查看各个 Runner 的状态
gitlab-runner stop 停止服务
gitlab-runner start 启动服务
gitlab-runner restart 重启服务

注册

需要先获取令牌。详细步骤请移步文章顶部参考博文。

.gitlab-ci.yml配置

这个文件大家参考意义不大,调用的命令很多是自定义的。博主主要是想记录下。

variables:
  # 构建结果发送邮件(服务端python实现)
  RECIEVER: xxx@yyy.com;
  SYS_NAME: jinghailu
  BASE_DIR: /export/App/
  BACKUP_DIR: /export/App/bak/
  BUILD_DIR: ./_build/
  DEV_ALPHA_IP: **.**.**.**
  DEV_DATABANK_IP: **.**.**.**
  # 三个IP分别对应国内、泰国、印尼
  UAT_IP: **.**.**.** **.**.**.** **.**.**.**

.env_init: &env_init |
  # develop / master
  IP_LIST="${UAT_IP}"

  # 从分支dev-alpha提交代码并push
  if [[ "${CI_COMMIT_REF_NAME}" == "dev-alpha" ]]; then
  IP_LIST="${DEV_ALPHA_IP}"
  fi

  # 从分支dev-databank提交push
  if [[ "${CI_COMMIT_REF_NAME}" == "dev-databank" ]]; then
  IP_LIST="${DEV_DATABANK_IP}"
  fi

  #if [[ -n "${CI_COMMIT_TAG}" ]]; then
  #IP_LIST="${UAT_IP}"
  #fi

before_script:
  - *env_init
# - PATH=$PATH:/export/servers/node-v10.15.1/bin/

cache:
  key: "$CI_COMMIT_REF_NAME"
  paths:
    - node_modules/
    - deploy.tar.gz

# for uat env
package-develop:
  stage: build
  script:
    - npm install
    - npm run build:uat
    - mkdir $BUILD_DIR
    - cp -r ./dist/ $BUILD_DIR/resource
    - cp -r ./jdos/* $BUILD_DIR
    - chmod a+x $BUILD_DIR/bin/*
    - cd $BUILD_DIR && tar czvf ../deploy.tar.gz * && cd ..
    - download_url=`upload-deploy-package -f deploy.tar.gz -r ${SYS_NAME}/${CI_COMMIT_REF_NAME}.tar.gz`
    - my-sendmail -s "publish-${SYS_NAME}" -c "You could deploy in jdos now! </br></br> <b>Branch:</b>&nbsp;${CI_COMMIT_REF_NAME} </br> <b>Commit:</b>&nbsp;${CI_COMMIT_MESSAGE} </br> <b>Commit Author:</b>&nbsp;${GITLAB_USER_NAME} </br> <b>Download Url:</b>&nbsp;${download_url}" -r "$RECIEVER"
  only:
    - develop
    - dev-alpha
    - dev-databank

# for master env
package-master:
  stage: build
  script:
    - npm install
    - npm run build
    - mkdir $BUILD_DIR
    - cp -r ./dist/ $BUILD_DIR/resource
    - cp -r ./jdos/* $BUILD_DIR
    - chmod a+x $BUILD_DIR/bin/*
    - cd $BUILD_DIR && tar czvf ../deploy.tar.gz * && cd ..
    - download_url=`upload-deploy-package -f deploy.tar.gz -r ${SYS_NAME}/${CI_COMMIT_REF_NAME}.tar.gz`
    - my-sendmail -s "publish-${SYS_NAME}" -c "You could deploy in jdos now! </br></br> <b>Branch:</b>&nbsp;${CI_COMMIT_REF_NAME} </br> <b>Commit:</b>&nbsp;${CI_COMMIT_MESSAGE} </br> <b>Commit Author:</b>&nbsp;${GITLAB_USER_NAME} </br> <b>Download Url:</b>&nbsp;${download_url}" -r "$RECIEVER"
  only:
    - master

# Auto Deploy
deploy:
  stage: deploy
  script:
    - echo $IP_LIST
    - for ip in $IP_LIST; do
    - echo $ip
    # backup files
    - ssh admin@$ip "cd $BASE_DIR && mkdir -p $BACKUP_DIR && tar czvf /export/App/bak/resource-`date +%Y%m%d%H`.tar.gz resource/ bin/"
    # stop service
    - ssh admin@$ip "cd /export/App/bin && /export/App/bin/stop.sh"
    # send file
    - scp deploy.tar.gz admin@$ip:$BASE_DIR
    # deploy files
    - ssh admin@$ip "cd $BASE_DIR && \rm -rf ./resource && tar xzvf deploy.tar.gz && \rm deploy.tar.gz"
    # work only in pre-production env
    # - ssh admin@$ip "cd $BASE_DIR/nginx && \cp jinghailu.jd.com_yufa agent"
    # start service
    - ssh admin@$ip "cd /export/App/bin && /export/App/bin/start.sh"
    - done
    - my-sendmail -s "deploy-${SYS_NAME}" -c "Deployed successfully! </br></br> <b>Branch:</b>&nbsp;${CI_COMMIT_REF_NAME} </br> <b>Commit:</b>&nbsp;${CI_COMMIT_MESSAGE} </br> <b>Commit Author:</b>&nbsp;${GITLAB_USER_NAME}" -r "$RECIEVER"
  only:
    - master
    - develop
    - dev-alpha
    - dev-databank

笔记

处理流程:

  1. 制定分支push
  2. 构建阶段 - 安装依赖(服务端每次拉取最新代码时更新依赖库)
  3. 构建阶段 - 执行打包命令
  4. 构建阶段 - 压缩包传到oss平台
  5. 构建阶段 - 发送邮件,附oss访问地址
  6. 部署阶段 - 遍历IP,从oss拉包到部署服务器,启动脚本

Tip:

  • 相同 Stage 中的 Jobs 会并行执行
  • job越少耗时越短。尝试过拆分更细粒度的阶段,阶段越多耗时越长。故最终还是只用了2个阶段。

1582977998917.jpg

今天关于gitlab 中的 Git 克隆在 linux 上失败,而在 Windows git bash 中工作git从gitlab上克隆项目的介绍到此结束,谢谢您的阅读,有关22.13-22.17 搭建 git 服务器,安装 gitlab, 使用 gitlab,gitlab 备份与恢复、Anaconda/Git:git branch 命令虽然在 WSL Ubuntu 中工作,但它是无声的、Android Gitlab CI作业在“ PlayStore:设备是否支持Google Play?”上失败、CICD持续集成: .gitlab-ci.yml配置小记(gitlab-ci + gitlab-runner)等更多相关知识的信息可以在本站进行查询。

本文标签: