云计算_CI/CD_devOps_集成_Gitlab
2022/3/10 23:17:26
本文主要是介绍云计算_CI/CD_devOps_集成_Gitlab,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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/CD_devOps_集成_Gitlab的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-13PingCAP 戴涛:构建面向未来的金融核心系统
- 2024-05-09flutter3.x_macos桌面os实战
- 2024-05-09Rust中的并发性:Sync 和 Send Traits
- 2024-05-08使用Ollama和OpenWebUI在CPU上玩转Meta Llama3-8B
- 2024-05-08完工标准(DoD)与验收条件(AC)究竟有什么不同?
- 2024-05-084万 star 的 NocoDB 在 sealos 上一键起,轻松把数据库编程智能表格
- 2024-05-08Mac 版Stable Diffusion WebUI的安装
- 2024-05-08解锁CodeGeeX智能问答中3项独有的隐藏技能
- 2024-05-08RAG算法优化+新增代码仓库支持,CodeGeeX的@repo功能效果提升
- 2024-05-08代码报错不用愁,CodeGeeX一键完成代码修复、错误解释的功能上线了!