ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

云计算_CI/CD_devOps_集成_Gitlab

2022-03-10 14:02:40  阅读:192  来源: 互联网

标签:CI git Merge Gitlab devOps merge commit 分支


Git和Gitlab

开发多年,git不能说特别熟悉,至少了解不少,
        常用的  git config git status,git add  ,git commit ,git push ,git clone, git pull,git init等,
  在多年前的自建的博客中就已经用的很顺手了,,对底层的概念也做过大致的研究,
  而现在则要根据项目,重现研习一下,git在项目中的使用了
Gitlab基于Git,但不停留在Git上,有自己特有的一些概念和使用

Git glossary

术语  git help glossary
远程 remote repository
     remote  origin
	  branch master
本地 local repository
   本地工作区: working directory
   本地暂存区: Staging Area    一般存放在 .git 目录下的 index 文件(.git/index)中
            git  commit 
	版本库:工作区有一个隐藏目录 .git
	
进一步了解
     git checkout
	 
	 git help glossary
本地常用操作
    	 git diff
		 git commit
		 git reset      将…恢复原位
		 git rm  git mv  git log
		 
		 RESET:重启系统、复位系统
     分支操作
	     创建分支命令   git branch (branchname)
		      列出分支  git branch
		 切换分支命令   git checkout (branchname)
		 创建并切换分支 git checkout -b (branchname) 命令来创建新分支并立即切换到该分支下,从而在该分支中操作
		 删除分支       git branch -d (branchname)
		 合并分支命令   git merge
		                git 
			
          rebase 合并多个commit为一个完整commit	
             git rebase -i HEAD~3 
              pick:保留该commit(缩写:p)  squash:将该commit和前一个commit合并(缩写:s)	
              drop:我要丢弃该commit(缩写:d)	
              reword:保留该commit,但我需要修改该commit的注释(缩写:r) 
			     edit:保留该commit, 但我要停下来修改该提交(不仅仅修改注释)(缩写:e)			
		 git revert HEAD  撤销提交
		 git reset HEAD   丢弃提交
		 
	HEAD	 HEAD指向所在的分支--HEAD指针总是通过分支指针,间接的指向了当前分支的最新提交--前分支的别名					
	commit id  
	git tag  
	       如果你达到一个重要的阶段,并希望永远记住那个特别的提交快照,你可以使用 git tag 给它打上标签
		   指向某个 commit 的指针,某个commit绑在一起

GitLab glossary

权限管理及Merge Request
 GitLab的Merge Request   
 GitLab中的角色分为以下5种:Guest、Reporter、Developer、Maintainer、Owner	
     Maintainer能够push代码到受保护分支,
	 而Developer只能创建Merge Requests
  jobs issues	 
  Gitlab UI
      Settings -> Repository -> Protected Branches	
  Merger Request
      Merge method: Merge commit / merge commit with semi-linear history /fast-forward merge
	  Merge options
	  Merge checks
	  Merge suggestions
	  Squash commits when Mergeing
      
 Source branch	   Target branch 
	  Git stash
	 
GitLab  Web页面
 Sma
   Project Information
   Repository: Files Commits  Branch Tags
                Contributors 
   Issues List  Board  Milestones
   Merege requests: New merge request  / edit merge requests
   CI/CD : Pipelines Editor Jobs Schedules
   Deployments
   Settings : GEneral    Integrations Repository CI/CD
   
  应用: Settings-->CI/CD-->Runners页面可以查看到是否有可用的Runner。
         Lint 的嵌入式调试工具,该工具可以验证 .gitlab-ci.yml 文件的内容  项目 -> CI/CD -> Pipelines

DevOps-工作模式

01.分支管理模式: 把项目的开发分为四个阶段:开发、测试、预发布和发布
      commit之前不喜欢pull下最新代码 导致会有merge commit,经常也会遇到冲突
02.Merge Request模式--开源长采用	
     gitlab上发起merge request 将自己的分支合并到feature分支上并且指定review的人员 Review通过后由其merge
	 merge request的作用其实就是多了一层review 由指定的人员review之后再merge
	 git rebase 变基rebase这个操作重新选定当前提交的根节点
	 
Gitlab  Branch和Tag
        Issue 议题  Milestone 里程碑
    用 milestone 标识阶段目标,对阶段性目标进行细化,化整为零成一个个的 issues	
    用issues 一个议题表示一个功能、一个bug、一个建议	
       Comment和Discussion		 
		
 DevOps
    Plan Create Verify Release
    Configure Manage Monitor Secure
	
 多分支
    对于多分支的代码库,将代码从一个分支转移到另一个分支是常见需求
	   需要另一个分支的所有代码变动,那么就采用合并(git merge)
	   只需要部分代码变动(某几个提交),这时可以采用 Cherry pick-指定的提交(commit)应用于其他分支。
	   
 Git flow	 
 Github flow -- Pull Request  是github的概念,不是git的概念 请对方做一个git fetch拿到request中的代码commits,然后git merge一下到某个分支上。
 Gitlab flow -- Merge Requests
    基于"版本发布"的,目标是一段时间以后产出一个新版本
    网站项目是"持续发布",代码一有变动,就部署一次	 
	  protected branch
##Gitlab支持软件开发的全流程

Gitlab触发 CI pipeline

 1.GitLab代码提交或推送触发CI pipeline,需要满足以下2点条件:
  01.仓库根目录下存在有 .gitlab-ci.yml 文件
  02.该项目有可用的 GitLab Runner
  
 2.一次构建任务-Types of pipelines
   Pipelines for Merge Requests
      Merge request pipelines run for merge requests only (rather than for every commit).
   pipelines for tags        
   
 
 3.variables
    01.预定义变量
	    有值
		特定条件下有值  CI_COMMIT_TAG  The commit tag name. Available only in pipelines for tags.
	02.自定义变量
	    Variable type variables
	    File type variables:
	
	作业包括外部YAML文件。也可用:include:local,include:file,include:template,和include:remote。
	tags 关键词是用于指定Runner
	only  只有在**分支可以运行
	
04.shell脚本
    export MODULE_NAME=`echo ${CI_COMMIT_TAG}|cut -d # -f 1`
    export TAG_VERSION=`echo ${CI_COMMIT_TAG}|cut -d # f 2 -`
	eval MODULE_VERSION=\${${MODULE_NAME}_VERSION} && export MODULE_VERSION
	
	eval MODULE_VERSION=\${${MODULE_NAME}_VERSION} | export MODULE_VERSION 管道符是有输出的情况,这种事同时成立,使用and符号
05.调用Dockerfile文件
  .Dockerfile中使用其定义的变量,同时使用自定义的entrypoint.sh,注意定义变量的scope 作用域

Tag

   git tag
  .gitlab-ci.yml file
   config.toml file

    git tag
.gitlab-ci.yml file
 only
 except
 rules
 config.toml file
  config.toml
    [[runners]]
      name   url  token
    environment  executor  shell tags

参考

 https://docs.gitlab.com/ee/topics/use_gitlab.html
 https://docs.gitlab.com/ee/topics/build_your_application.html

标签:CI,git,Merge,Gitlab,devOps,merge,commit,分支
来源: https://www.cnblogs.com/ytwang/p/15989190.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有