CI的技术手段: Git +Shell + Jekins,频繁的将代码集成到主干。
CD: 持续交付
CD: 持续部署, 是持续交付的下一步,代码通过评审以后,自动部署到生产环境。
版本控制系统 Git:
主要是开放需要使用,对代码进行版本管理。
GIT的全称是"Global Information Tracker",请注意这是一个开玩笑的解释,而不是GIT实际的全称。实际上,GIT并没有一个正式的全称,它只是被称为"GIT"
GIT,CVS,SVN 是三种版本控制系统的缩写。CVS:CVS(Concurrent Versions System)是一种集中式版本控制系统. SVN:SVN(Subversion)是一种集中式版本控制系统.
GIT:GIT是一种分布式版本控制系统,
1. 安装git (关掉防火墙,配置好yum源)
[root@master ~]#yum install -y git
[root@master ~]# git --version
git version 1.8.3.1
[root@master ~]#
~/.bash_profile 当前用户变量
Advanced Packaging Tool - APT
基于deban的ubuntu :
# apt-get install git
windows 下载安装:
当前{BANNED}最佳新版本是 Git-2.41.0-64-bit.exe
$ git --version
git version 2.41.0.windows.1
1.9 Git 信息配置
git config 来控制git的行为,定义环境变量。 git config --global/system/local xxx.xx
--system ##针对任意登录linux系统的用户都生效。 写入/etc/gitconfig
--global ##全局,用的最多, 只针对当前登录的用户生效。写入~/.config/git/config也就是当前用户的家目录下。
--local ## 本地,只针对某个文件夹。
当使用git config --global/system/local xxx.xx 命令配置git的环境变量的时候,不同的参数会写入信息到不同的文件中。
用户GIT信息配置
使用GIT前,先配置GIT信息。
[root@node2 ~]# git config --global user.name "username"
[root@node2 ~]# git config --global user.email "email_name@outlook.com"
[root@node2 ~]# git config --global color.ui true
就像linux的环境变量, /etc/profile; 系统级的位于/etc/bashrc,对所有用户生效; 用户级的位于~/.bashrc
一般不建议在/etc/profile文件中添加环境变量,因为在这个文件中添加的设置会对所有用户起作用. 添加环境变量后,需要重新登录才能生效,也可以使用 source 命令强制立即生效:
bash_profile只对单一用户有效,文件存储位于~/.bash_profile,该文件是一个用户级的设置,可以理解为某一个用户的 profile 目录下。
这三种文件类型的差异用一句话表述就是:
--------------------------------------------------
1.11 Git 如何使用的三个场景
场景1: 本地文件夹。 本地文件里面有代码,用git管理。只要用git init进行初始化就可以了。
[root@node2 ~]# mkdir /local_git
[root@node2 ~]# cd /local_git/
[root@node2 local_git]# ls
[root@node2 local_git]# ls -al
total 0
drwxr-xr-x 2 root root 6 Jul 10 20:53 .
dr-xr-xr-x. 18 root root 261 Jul 10 20:53 ..
[root@node2 local_git]# ls -a
. ..
[root@node2 local_git]#
[root@node2 local_git]#
[root@node2 local_git]# ls -al
total 0
drwxr-xr-x 2 root root 6 Jul 10 20:53 .
dr-xr-xr-x. 18 root root 261 Jul 10 20:53 ..
[root@node2 local_git]#
[root@node2 local_git]# git init .
Initialized empty Git repository in /local_git/.git/
[root@node2 local_git]#
[root@node2 local_git]# ls -al
total 0
drwxr-xr-x 3 root root 18 Jul 10 20:53 .
dr-xr-xr-x. 18 root root 261 Jul 10 20:53 ..
drwxr-xr-x 7 root root 119 Jul 10 20:53 .git
[root@node2 local_git]#
[root@node2 local_git]# ls
Jekins 工具学习git config 来控制git的行为,定义环境变量。 git config --global/system/local xxx.xx
--system ##针对任意登录linux系统的用户都生效。 写入/etc/gitconfig
--global ##全局,用的最多, 只针对当前登录的用户生效。写入~/.config/git/config也就是当前用户的家目录下。
--local ## 本地,只针对某个文件夹。
当使用git config --global/system/local xxx.xx 命令配置git的环境变量的时候,不同的参数会写入信息到不同的文件中。
用户GIT信息配置
使用GIT前,先配置GIT信息。
[root@node2 ~]# git config --global user.name "username"
[root@node2 ~]# git config --global user.email "email_name@outlook.com"
[root@node2 ~]# git config --global color.ui true
[root@node2 ~]# git config --global --list
user.name=username
user.email=email_name@outlook.com
color.ui=true
[root@node2 ~]#
[root@node2 ~]# cat /root/.gitconfig
[user]
name = username
email = email_name@outlook.com
[color]
ui = true
[root@node2 ~]# cat ~/.gitconfig
[user]
name = username
email = email_name@outlook.com
[color]
ui = true
[root@node2 ~]#
----------------------------------------user.name=username
user.email=email_name@outlook.com
color.ui=true
[root@node2 ~]#
[root@node2 ~]# cat /root/.gitconfig
[user]
name = username
email = email_name@outlook.com
[color]
ui = true
[root@node2 ~]# cat ~/.gitconfig
[user]
name = username
email = email_name@outlook.com
[color]
ui = true
[root@node2 ~]#
[root@node2 ~]# git config --system user.name "system_user_name"
[root@node2 ~]# git config --system user.email "system_user_email_888@outlook.com"
[root@node2 ~]# cat /etc/gitconfig
[user]
name = system_user_name
email = system_user_email_888@outlook.com
[root@node2 ~]# git config --system --list
user.name=system_user_name
user.email=system_user_email_888@outlook.com
[root@node2 ~]#
[root@node2 ~]# git config --system user.email "system_user_email_888@outlook.com"
[root@node2 ~]# cat /etc/gitconfig
[user]
name = system_user_name
email = system_user_email_888@outlook.com
[root@node2 ~]# git config --system --list
user.name=system_user_name
user.email=system_user_email_888@outlook.com
[root@node2 ~]#
[root@node2 ~]# git config --global --list
user.name=username
user.email=email_name@outlook.com
color.ui=true
[root@node2 ~]#
user.name=username
user.email=email_name@outlook.com
color.ui=true
[root@node2 ~]#
[root@node2 ~]# git help
usage: git [--version] [--help] [-c name=value]
[--exec-path[=]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=] [--work-tree=] [--namespace=]
[]
usage: git [--version] [--help] [-c name=value]
[--exec-path[=]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=] [--work-tree=] [--namespace=]
[]
就像linux的环境变量, /etc/profile; 系统级的位于/etc/bashrc,对所有用户生效; 用户级的位于~/.bashrc
一般不建议在/etc/profile文件中添加环境变量,因为在这个文件中添加的设置会对所有用户起作用. 添加环境变量后,需要重新登录才能生效,也可以使用 source 命令强制立即生效:
source /etc/profile
bash_profile只对单一用户有效,文件存储位于~/.bash_profile,该文件是一个用户级的设置,可以理解为某一个用户的 profile 目录下。
这三种文件类型的差异用一句话表述就是:
/etc/profile,/etc/bashrc 是系统全局环境变量设定;
~/.profile,~/.bashrc用户家目录下的私有环境变量设定。
首先读入全局环境变量设定档/etc/profile,然后根据其内容读取额外的设定的文档,如/etc/profile.d和/etc/inputrc;- 根据不同使用者帐号,于其家目录内读取~/.bash_profile;
- 读取失败则会读取~/.bash_login;
- 再次失败则读取~/.profile(这三个文档设定基本上无差别,仅读取上有优先关系);
- 最后,根据用户帐号读取~/.bashrc。
至于~/.profile与~/.bashrc都具有个性化定制功能,但~/.profile可以设定本用户专有的路径、环境变量等,它只能登入的时候执行一次。
~/.bashrc也是某用户专有设定文档,可以设定路径、命令别名,每次 shell script 的执行都会使用它一次。
bashrc 文件只会对指定的 shell 类型起作用,bashrc 只会被 bash shell 调用。--------------------------------------------------
1.11 Git 如何使用的三个场景
场景1: 本地文件夹。 本地文件里面有代码,用git管理。只要用git init进行初始化就可以了。
[root@node2 ~]# mkdir /local_git
[root@node2 ~]# cd /local_git/
[root@node2 local_git]# ls
[root@node2 local_git]# ls -al
total 0
drwxr-xr-x 2 root root 6 Jul 10 20:53 .
dr-xr-xr-x. 18 root root 261 Jul 10 20:53 ..
[root@node2 local_git]# ls -a
. ..
[root@node2 local_git]#
[root@node2 local_git]#
[root@node2 local_git]# ls -al
total 0
drwxr-xr-x 2 root root 6 Jul 10 20:53 .
dr-xr-xr-x. 18 root root 261 Jul 10 20:53 ..
[root@node2 local_git]#
[root@node2 local_git]# git init .
Initialized empty Git repository in /local_git/.git/
[root@node2 local_git]#
[root@node2 local_git]# ls -al
total 0
drwxr-xr-x 3 root root 18 Jul 10 20:53 .
dr-xr-xr-x. 18 root root 261 Jul 10 20:53 ..
drwxr-xr-x 7 root root 119 Jul 10 20:53 .git
[root@node2 local_git]#
或者直接 git init /local_git 也是同样的效果。
[root@node2 local_git]# git init /local_git2
Initialized empty Git repository in /local_git2/.git/
[root@node2 local_git]# ls -al /local_git2
total 0
drwxr-xr-x 3 root root 18 Jul 10 21:08 .
dr-xr-xr-x. 19 root root 279 Jul 10 21:08 ..
drwxr-xr-x 7 root root 119 Jul 10 21:08 .git
[root@node2 local_git]#
total 20
drwxr-xr-x 5 root root 97 Jul 10 21:20 .
drwxr-xr-x 3 root root 27 Jul 10 21:20 ..
drwxr-xr-x 8 root root 163 Jul 10 21:25 .git
-rw-r--r-- 1 root root 10 Jul 10 21:20 .gitignore
drwxr-xr-x 3 root root 58 Jul 10 21:20 kcptun
-rw-r--r-- 1 root root 11357 Jul 10 21:20 LICENSE
drwxr-xr-x 7 root root 100 Jul 10 21:20 ovz-bbr
-rw-r--r-- 1 root root 1647 Jul 10 21:20 README.md
[root@node2 shell-scripts]#
git status查看暂存区域有没有信息
[root@node2 local_git]# git init /local_git2
Initialized empty Git repository in /local_git2/.git/
[root@node2 local_git]# ls -al /local_git2
total 0
drwxr-xr-x 3 root root 18 Jul 10 21:08 .
dr-xr-xr-x. 19 root root 279 Jul 10 21:08 ..
drwxr-xr-x 7 root root 119 Jul 10 21:08 .git
[root@node2 local_git]#
从github上面下载代码,打开 搜索shell script, 找到下载的路径

[root@node2 github]# git clone /kuoruan/shell-scripts.git
Cloning into 'shell-scripts'...
remote: Enumerating objects: 424, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 424 (delta 2), reused 6 (delta 2), pack-reused 416
Receiving objects: 100% (424/424), 16.10 MiB | 4.40 MiB/s, done.
Resolving deltas: 100% (189/189), done.
[root@node2 github]#
[root@node2 shell-scripts]# ls -al /github/shell-scripts/[root@node2 github]# git clone /kuoruan/shell-scripts.git
Cloning into 'shell-scripts'...
remote: Enumerating objects: 424, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 424 (delta 2), reused 6 (delta 2), pack-reused 416
Receiving objects: 100% (424/424), 16.10 MiB | 4.40 MiB/s, done.
Resolving deltas: 100% (189/189), done.
[root@node2 github]#
total 20
drwxr-xr-x 5 root root 97 Jul 10 21:20 .
drwxr-xr-x 3 root root 27 Jul 10 21:20 ..
drwxr-xr-x 8 root root 163 Jul 10 21:25 .git
-rw-r--r-- 1 root root 10 Jul 10 21:20 .gitignore
drwxr-xr-x 3 root root 58 Jul 10 21:20 kcptun
-rw-r--r-- 1 root root 11357 Jul 10 21:20 LICENSE
drwxr-xr-x 7 root root 100 Jul 10 21:20 ovz-bbr
-rw-r--r-- 1 root root 1647 Jul 10 21:20 README.md
[root@node2 shell-scripts]#
git status查看暂存区域有没有信息
[root@node2 shell-scripts]# git status
# On branch master
nothing to commit, working directory clean
[root@node2 shell-scripts]#
# On branch master
nothing to commit, working directory clean
[root@node2 shell-scripts]#
现在我创建一个脚本,也就是一个文件。
[root@node2 shell-scripts]# touch newscript.sh
[root@node2 shell-scripts]# git status
# On branch master
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# newscript.sh
nothing added to commit but untracked files present (use "git add" to track)
[root@node2 shell-scripts]#
[root@node2 shell-scripts]# touch newscript.sh
[root@node2 shell-scripts]# git status
# On branch master
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# newscript.sh
nothing added to commit but untracked files present (use "git add" to track)
[root@node2 shell-scripts]#
这时候有一个untracked 的files存在了。 文件内容变化以后,要执行git add . 就会将文件内容的变化状态写入到暂存区域。
git add . 就是添加到暂存区。 changes to be committed 就是等待提交。
[root@node2 shell-scripts]# git add .
[root@node2 shell-scripts]#
[root@node2 shell-scripts]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# new file: newscript.sh
#
[root@node2 shell-scripts]#
git add . 就是添加到暂存区。 changes to be committed 就是等待提交。
[root@node2 shell-scripts]# git add .
[root@node2 shell-scripts]#
[root@node2 shell-scripts]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# new file: newscript.sh
#
[root@node2 shell-scripts]#
1.12 第一次提交git版本库
1. 生成git工作区
[root@node2 /]# git init git_work_area
Initialized empty Git repository in /git_work_area/.git/
[root@node2 /]# ls -al git_work_area
total 4
drwxr-xr-x 3 root root 18 Jul 10 21:55 .
dr-xr-xr-x. 21 root root 4096 Jul 10 21:55 ..
drwxr-xr-x 7 root root 119 Jul 10 21:55 .git
[root@node2 /]#
[root@node2 ~]# cd /local_git/
1. 生成git工作区
[root@node2 /]# git init git_work_area
Initialized empty Git repository in /git_work_area/.git/
[root@node2 /]# ls -al git_work_area
total 4
drwxr-xr-x 3 root root 18 Jul 10 21:55 .
dr-xr-xr-x. 21 root root 4096 Jul 10 21:55 ..
drwxr-xr-x 7 root root 119 Jul 10 21:55 .git
[root@node2 /]#
2. 查看git工作区中的本地仓库
[root@node2 /]# ls -al /git_work_area/
total 4
drwxr-xr-x 3 root root 18 Jul 10 21:55 .
dr-xr-xr-x. 21 root root 4096 Jul 10 21:55 ..
drwxr-xr-x 7 root root 119 Jul 10 21:55 .git
[root@node2 /]#
[root@node2 /]# yum install -y tree
tree命令可以树状查看内容,
[root@node2 git_work_area]# tree /git_work_area/.git/
/git_work_area/.git/
├── branches
├── config #该项目独有的配置文件
├── description
├── HEAD #git的文件指针
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── info
│ └── exclude
├── objects
│ ├── info
│ └── pack
└── refs
├── heads
└── tags
9 directories, 13 files
[root@node2 git_work_area]#
[root@node2 git_work_area]# touch test1.sh
[root@node2 git_work_area]# git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# test1.sh
nothing added to commit but untracked files present (use "git add" to track)
[root@node2 git_work_area]# git add .
[root@node2 git_work_area]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: test1.sh
[root@node2 git_work_area]# git commit -m "first commit for test1"
[master (root-commit) 5366710] first commit for test1
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test1.sh
[root@node2 git_work_area]# git status
# On branch master
nothing to commit, working directory clean
[root@node2 git_work_area]#

“git init 文件夹” 生成工作目录, 然后 “git add .” 添加到暂存区域,然后“git commit -m” 提交到本地仓库。
上面3条命令就是git管理文件的流程,并且提交到本地仓库。
1.13
第2章 Gitlab代码托管平台
2.2 码云代码推送的2个方式
新建仓库
1. 右上角,点 + ,然后选"新建仓库"



[root@node2 /]# ls -al /git_work_area/
total 4
drwxr-xr-x 3 root root 18 Jul 10 21:55 .
dr-xr-xr-x. 21 root root 4096 Jul 10 21:55 ..
drwxr-xr-x 7 root root 119 Jul 10 21:55 .git
[root@node2 /]#
tree命令可以树状查看内容,
[root@node2 git_work_area]# tree /git_work_area/.git/
/git_work_area/.git/
├── branches
├── config #该项目独有的配置文件
├── description
├── HEAD #git的文件指针
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── info
│ └── exclude
├── objects
│ ├── info
│ └── pack
└── refs
├── heads
└── tags
9 directories, 13 files
[root@node2 git_work_area]#
[root@node2 git_work_area]# git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# test1.sh
nothing added to commit but untracked files present (use "git add" to track)
[root@node2 git_work_area]# git add .
[root@node2 git_work_area]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: test1.sh
[root@node2 git_work_area]# git commit -m "first commit for test1"
[master (root-commit) 5366710] first commit for test1
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test1.sh
[root@node2 git_work_area]# git status
# On branch master
nothing to commit, working directory clean
[root@node2 git_work_area]#
“git init 文件夹” 生成工作目录, 然后 “git add .” 添加到暂存区域,然后“git commit -m” 提交到本地仓库。
1.13
第2章 Gitlab代码托管平台
2.2 码云代码推送的2个方式
新建仓库
1. 右上角,点 + ,然后选"新建仓库"
[root@node2 ~]# cd /local_git/
[root@node2 local_git]# ls
[root@node2 local_git]# ls -al
total 0
drwxr-xr-x 2 root root 6 Jul 10 20:53 .
dr-xr-xr-x. 18 root root 261 Jul 10 20:53 ..
[root@node2 local_git]# ls -a
. ..
[root@node2 local_git]#
[root@node2 local_git]#
[root@node2 local_git]# ls -al
total 0
drwxr-xr-x 2 root root 6 Jul 10 20:53 .
dr-xr-xr-x. 18 root root 261 Jul 10 20:53 ..
[root@node2 local_git]#
[root@node2 local_git]# git init .
Initialized empty Git repository in /local_git/.git/
[root@node2 local_git]#
[root@node2 local_git]# ls -al
total 0
drwxr-xr-x 3 root root 18 Jul 10 20:53 .
dr-xr-xr-x. 18 root root 261 Jul 10 20:53 ..
drwxr-xr-x 7 root root 119 Jul 10 20:53 .git
[root@node2 local_git]#
[root@node2 ~]#
mkdir /local_gitGit如何用的三个场景
Git如何用的三个场景
搭建Jekins+Shell
鼠标轻轻一点,项目自动更新上线。