User-Profile-Image
hankin
  • 5
  • centos7
  • docker
  • mysql
  • PostgreSQL
  • git/gitlab
  • ELK
  • python
    • python-Tornado
    • python-django
  • redis
  • nginx
  • kvm
  • proxmox
  • mongo
  • kubernetes
  • prometheus
  • GlusterFs
  • nfs
  • freeswitch
  • httpd
  • shell脚本
  • linux
  • fastdfs
  • nextcloud
  • openssl
  • openvpn
  • rabbitmq
  • sqlite
  • svn
  • java
  • ubuntu
  • vue2
  • wordpress
  • php
  • IOT物联网
  • 项目
  • 故障处理
  • 树莓派
  • 博客存档
  • 未分类
  • 杂项
  • #1742(无标题)
  • 新视野
  • 分类
    • 项目
    • 树莓派
    • 杂项
    • 未分类
    • 新视野
    • 故障处理
    • 博客存档
    • 交换机
    • wordpress
    • vue2
    • ubuntu
    • svn
    • sqlite
    • shell脚本
    • redis
    • rabbitmq
    • python-django
    • python
    • proxmox
    • prometheus
    • PostgreSQL
    • php
    • openvpn
    • openssl
    • nginx
    • nfs
    • nextcloud
    • mysql
    • mongo
    • linux
    • kvm
    • kubernetes
    • java
    • IOT物联网
    • httpd
    • GlusterFs
    • git/gitlab
    • freeswitch
    • fastdfs
    • ELK
    • docker
    • centos7
  • 页面
    • #1742(无标题)
  • 友链
      请到[后台->主题设置->友情链接]中设置。
Help?

Please contact us on our email for need any support

Support
    首页   ›   git/gitlab   ›   正文
git/gitlab

gitlab配置CI/CD流水线

2023-04-25 11:37:40
31  0 0
说明
gitlab配置CI/CD流水线,基于gitlab版本15.11
先以最简单的配置运行起来,分解难度,跑通了再深入学习实践
安装启动runner
安装参考https://www.tang.show/docker/runner/
#直接在centos7系统安装,选shell类型,降低困难度
检查gitlab项目页面地址
对于自己部署的runner如果地址不是ip或域名,需要设置下否则cicd无法拉代码
    设置成ip参考https://www.tang.show/git-gitlab/docker%e5%ae%89%e8%a3%85gitlab/
    中的初始化配置>>设置url地址|设置gitlab克隆地址
    然后执行gitlab-ctl reconfigure 和gitlab-ctl restart #重载、重启

注册runner
可在gitlab页面http://192.168.2.32/admin/runners页面获取token信息或复制快捷命令
然后在安装runner的机器上执行:
    gitlab-runner register --url http://192.168.2.32/ --registration-token xxxzCZHvrsa Runtime platform arch=amd64 os=linux pid=38319 revision=436955cb version=15.11.0 xx
    Enter the GitLab instance URL (for example, https://gitlab.com/):#回车
    [http://192.168.2.32/]: 
    Enter the registration token:#回车
    [3HjVKq225ryLzCZHvrsa]: 
    Enter a description for the runner:
    [localhost]: 
    Enter tags for the runner (comma-separated):#回车,设置为默认,这样yaml文件不用指定就能调用该runner
    Enter optional maintenance note for the runner:
    WARNING: Support for registration tokens and runner parameters in the 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with xx
    Registering runner... succeeded                     runner=3HjVKq22
    Enter an executor: ssh, virtualbox, docker-autoscaler, custom, docker, docker-windows, docker-sshx xx -ssh+machine:#直接输入shell,再回车
    shell
    Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
    #注册完成,gitlab页面查看,runner已上线
新建项目
创建一个项目,在根目录放置.gitlab-ci.yml,内容如下:
  pages:
  stage: deploy
  environment: production
  script:
    - echo "hello"
    - mkdir .public
    - cp -r ./* .public
    - rm -rf public
    - mv .public public
  artifacts:
    paths:
      - public
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
然后新一个任意文件,配置正确的会触发cicd流程按上配置执行
观察执行
如图,执行已完成:

登录runner执行 find / -name testabc,返回以下,代表已成功拉下项目,并且执行了yaml配置:
    /home/gitlab-runner/builds/2jw2Jm3g/0/gitlab-instance-f0987d43/r1/testabc
    /home/gitlab-runner/builds/2jw2Jm3g/0/gitlab-instance-f0987d43/r1/public/testabc、

在gitlab页面上也能查看执行的详情:

评论 (0)

点击这里取消回复。

欢迎您 游客  

Copyright © 2025 网站备案号 : 蜀ICP备2022017747号
smarty_hankin 主题. Designed by hankin
主页
页面
  • #1742(无标题)
博主
tang.show
tang.show 管理员
linux、centos、docker 、k8s、mysql等技术相关的总结文档
213 文章 2 评论 201907 浏览
测试
测试