Tag - gitlab

? gitlab ?    2021-01-06 15:19:23    1050    0    0
  1. gitlab web : User Setting --> Access Tokens

API_VERSION:

  1. https://gitlab.casa-systems.com/help/api/v3_to_v4.md
  2. In GitLab 9.0 and later, API V4 is the preferred version to be used.

jq command:

  1. https://stedolan.github.io/jq/manual/#Invokingjq



gitlab api 根据指定组名取组对象

  1. curl --header "PRIVATE-TOKEN: $P_token" $GITLAB_INSTANCE/api/$API_VERSION/groups/${GroupName} 2>/dev/null|jq .

gitlab api 根据指定组名取组里的元素属性

  1. curl --header "PRIVATE-TOKEN: $P_token" $GITLAB_INSTANCE/api/$API_VERSION/groups/${GroupName} 2>/dev/null|jq 'keys'

gitlab api 根据指定组名取组里的第一个project里的属性

  1. curl --header "PRIVATE-TOKEN: $P_token" $GITLAB_INSTANCE/api/$API_VERSION/groups/${GroupName} 2>/dev/null|jq .projects[0]|jq 'keys'

gitlab api 根据指定组名取组的任一key的值

  1. curl --header "PRIVATE-TOKEN: $P_token" $GITLAB_INSTANCE/api/$API_VERSION/groups/${GroupName
? gitlab ?    2019-11-04 16:22:09    2084    2    0

Push Rule


设置的位置 Gitlab project 的settings
repository -> Push Rules -> Commit message:

示例:

  1. ^(I|i)ssue \d{4,6} \/*
  2. ^(Issue|issue|bug|Bug) #\d{1,7} \/*

示例含义:

  1. ^(I|i)ssue 开头
  2. \d{4,6} 表示4-6位数字
  3. \/* 表示任意内容

即以上示例匹配以下格式:

  1. [I|i]ssue空格4-6位数字空格任意内容
  2. Issue 1234 gfdg dgdfgdfgdff
  3. Issue 124455 ggfdgd gd

其他匹配细节可参考:
https://github.com/google/re2/wiki/Syntax

不符合commit message匹配规则的commit 无法被push , 此时gitlab 会给出匹配提示,以实际项目中设置的格式为准,比如:

  1. remote: GitLab: Commit message does not follow the pattern '^(I|i)ssue \d{4,6} \/*'

以下介绍如何处理修正不匹配规则的commit message。

三种情况
- [1] gitlab web 页面直接提交时(即直接在远程push 一条commit)
- [2] 提交一个merge request 时,merge request 本身产生一条合并的commit
- [3] 本地仓库的commit 推送到远程仓库时

以上情况,在push时,会对commit message , 对merge reuqest 的title 进行上方设置规则的匹配校验,检验不成功则push 不成功。


gitlab web 页面直接提交时

title


提交一个merge request

title


本地仓库的commit 推送到远程仓库时

本地仓库的commit message 不符合匹配规则,导致在push这些不合规的commit到remote repo时报错:
--push failed: r

? gitlab ?    2019-11-04 16:07:22    23995    1    0

gitlab 的 release 功能是项目交付跟踪的一种方式


Gitlab 的release 功能不止将源代码快照(tag) 与版本对应记录,其他版本信息,如目标产物,修改说明,相关文档链接等,都可以在一个release 里跟踪。

目前在GitLab 11.7 以上版本已经包含了release 的功能,但是现在(2019-11-1)为止,Release 的入口只支持API接入。


更新信息:
Gitlab 的 release 现在已支持在界面上直接以 “new release” 进入编辑。
以下说明皆为使用 api 新建release 的方法:(此句更新于2021.5.6)


图片标题
https://docs.gitlab.com/ee/api/releases/index.html

官方文档相关说明


一个release 可以包含两大块资源: 代码和链接。后续会支持更多资源的关联,包含容器等

  1. Release assets
  2. You can currently add the following types of assets to each Release:
  3. Source code: state of the repo at the time of the Release
  4. Links: to content such as built binaries or documentation
  5. GitLab will support more asset types in the future, including objects such as pre-built packages, compliance/security evidence, or container images.

关联的资源


Source code

实际是映射到 tag 对应的源码版本 ,tag 信息是需要在创建release 时提供。

link

目前支持 http, https, ftp 链接。一个release 里可以有多个link , 每个link 用字典管理,分别有自己的 id tag_name n

? gitlab ?    2019-09-18 13:45:21    251    0    0
? shell ? ? gitlab ?    2019-09-18 10:38:35    652    0    0

JQ URL

https://stedolan.github.io/jq/download/
https://stedolan.github.io/jq/manual/#Invokingjq
这是一个开源工具,用于处理json 。

前言

"The API uses JSON to serialize data. You don’t need to specify .json at the end of an API URL."

在linux 下使用gitlab API 返回json 对象,经常使用python处理返回结果。 如果只是单纯地使用shell脚本中,常将其当作文本,并用sed ,grep,cut分解。但是因为它不是准确地分解对象中的组成,而是简单地通过关键字进行筛选和切割,所以经常会有遗漏或不够准确。

在linux 中安装jq , 可以在shell 中直接使用jq 对json 对象进行处理。

安装jq

下载 jq 源码包编译安装
  1. # configure ,make ,make install
  2. cd jq
  3. autoreconf -i
  4. ./configure --disable-maintainer-mode
  5. make
  6. sudo make install

下载二进制文件直接使用

  1. [root@huangbei ~]# chmod +x jq-linux64
  2. [root@huangbei ~]# mv jq-linux64 /usr/bin/jq
  3. [root@huangbei ~]# jq
  4. jq - commandline JSON processor [version 1.6]
  5. Usage: jq [options] <jq filter> [file...]
  6. jq [options] --args <jq filter> [strings...]
  7. jq [options] --jsonargs <jq filter> [JSON_TEXTS...]
  8. jq is a tool for processing JSON inputs, applying the given
? gitlab ?    2019-09-05 15:05:35    1212    0    0


User setting and access

 

User Settings

登录gitlab.XX-company.com 之后在页面右上角头像处点击∨展开菜单,进入setting。

可以设置相关用户信息,常用的包括profile(基本配置),Account(帐户),Preferences(偏好设置),密码,SSH Keys,Notifications(邮件通知范围),Active Session(有效的连接)


Profile

可以在profile 里修改头像,邮箱,状态,及各平台关联帐号

 

Account

可以在account里修改用户名,用户名标识着与用户id 唯一关联的名称空间。一般不建议修改,如果修改,可能引起一些未知的影响,如必要修改,请严格按照修改页面的learn more 到“changing-your-username”根据提示做足步骤。

https://gitlab.XX-company.com/help/user/profile/index#changing-your-username

 

Notifications

全局通知设置:先在全局设置里可以设置通知的级别,然后在然后组/项目里分别设置为不同级别。默认为全局设置,展开可选其他。

 

Password

密码页面,修改密码后,会收到一个邮件,点击链接可以使用新密码登录(稍有延迟)

 

SSH Keys

SSH密钥允许您在计算机和GitLab之间建立安全连接,使用较多的情况是,当我们使用SSH 来 Clone 一个项目时,需要先在gitlab里配置好ssh keys。

一般我们在项目主页里展开clone 选项时,有两种方式,一种是clone with SSH,一种是Clone with HTTPS

 

当我们使用clone with SSH 时,我们需要先配置好ssh keys。

https://gitlab.XX-company.com/help/ssh/README#generating-a-new-ssh-key-pair

步骤是,先在一台linux 设备上生成一个密钥对,公钥拷到gitlab设置页面里,私钥放到需要clone 项目的设置上的默认ssh 配置路径。然后就可以直接使用这样的链接进行clone

Git clone git@gitlab.XX-company.com:vmc/products.git

 

另有直接使用用户/密码

? gitlab ?    2019-03-27 14:56:31    475    0    0

写在前面

gitlab 的CI/CD ,即持续集成,持续构建并部署测试的过程,实质上是
1. 将持续集成的过程阶段(编译构建/打包/部署/测试)写在gitlab.yml中
2. 并将准备执行gitlab.yml脚本内容的服务器配置为gitlab服务器的一个runner。
3. 当gitlab 库中的提交时,便会自动触发一次在runner 上的持续集成过程。


创建 gitlab-ci.yml

注意: gitlab.yml 是一个yaml文件,对缩进非常严格,需要始终使用空格,而非制表符。
https://gitlab.${company}.com/help/ci/yaml/README.md
具体格式及构成可参考gitlab help/ci/yaml/README.md 文件

  1. 在库中的根目录下,创建一个名为.gitlab.yml的文件
  2. 1. 通过 CI-CD --> jobs --> CI Init 直接编辑初始化文件
  3. 2. 在库中的根目录下,创建一个名为.gitlab.yml的文件

配置库的CI/CD

  1. 在库的设置中Setting--> CI/CD --> runners 展开
  2. 使用共享 runner 去运行 Shared Runners
  3. 使用指定 runner 去运行 Specific Runners //如从新配置一台服务器作为gitlab.yml 中脚本运行的runner,请按如下配置runner执行

配置 Runner

https://docs.gitlab.com/runner/install/

安装GitLab Runner

  1. # Linux x86-64
  2. sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

赋执行权限

  1. sudo chmod +x /usr/local/bin/gitlab-runner

创建 GitLab CI 用户:

? gitlab ?    2019-03-26 17:10:57    369    0    0

  1. git reset test.txt #将指针后移
  2. git checkout test.txt #重新检出一份代码,检出的版本是当前workspace 最新的commit版本


test.txt :modify ,未add ,未commit

撤销修改内容

  1. git reset test.txt #无改变,因为未受控,未追踪
  2. git checkout test.txt #撤销修改内容

test.txt :modify ,add ,未commit

撤销 add

  1. git reset test.txt #返回到未add 的状态
  2. git checkout test.txt #撤销修改内容

test.txt :modify ,add ,commit

撤销commit

  1. ##对于修改已经commit 到本地仓库的
  2. git log -n 2 ##找到上一次commit pre-ID
  3. git reset pre-ID ## 将workspace 恢复到上一条commit,即撤销本次commit
  4. git status ## 可以看到文件又回到add 未commmit状态

对于本地仓库已经更新远程最新,想要撤销更新,回退到未更新前的某个commit 的位置

  1. git reset ID
  2. git status
  3. git checkout XXX XXXXfile

等于

  1. git reset --hard ID ## --hard 表示回退指针再恢复文件内容
  2. ## 即--hard == reset + checkout
  3. git status
  4. # 以下摘自https://git-scm.com/book/zh/v2
  5. 虽然在调用时加上 --hard 选项可以令 git reset 成为一个危险的命令(译注:可能导致工作目录中所有当前进度丢失!),但本例中工作目录内的文件并不会被修改。 不加选项地调用 git reset 并不危险 它只会修改暂存区域。
以上,恢复到远程某个commit 时的版本,等到远程稳定时再用git pull 就可以重新再更新到最新


? gitlab ?    2019-01-17 11:46:46    1337    1    0
? gitlab ?    2019-01-11 16:22:44    1643    0    2
1/2