gitlab-runner安装及使用教程

一、安装gitlab-runner
1.1 如果系统是centos系列,直接使用以下命令安装gitlab-runner yum源,并安装gitlab-runner
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash
yum install gitlab-runner
1.2 如果系统是centos变种,例如龙蜥8,可以使用以下命令安装gitlab-runner yum源,并安装gitlab-runner
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" > script.rpm.sh
chmod +x script.rpm.sh
os=el dist=8 ./script.rpm.sh
yum install gitlab-runner
2.1 如果系统是ubuntu系列,直接使用以下命令安装gitlab-runner apt-get源,并安装gitlab-runner
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
apt-get install gitlab-runner

二、注册gitlab-runner
1.1 进入gitlab admin area主界面,界面截图如下

1.2 点击CI/CD菜单下的Runners菜单,界面截图如下

1.3 点击New instance runner按钮,并填写必要的信息,界面截图如下

1.4 点击Create runner按钮,界面截图如下

1.5 在gitlab-runner安装好的机器中执行以下命令,输入注册名称,选择执行器类型,比如shell,即可注册成功
#--url为gitlab的external url地址
gitlab-runner register  --url https://newgitlab.com  --token glrt-GCTCASumzqyKyzrAA5qy
#如果gitlab的external url 地址是一个https 自签名域名,可以添加tls自签名证书信任,目录中需提前放好对应的域名证书
gitlab-runner register --url https://newgitlab.com --token glrt-GCTCASumzqyKyzrAA5qy --tls-ca-file="/etc/gitlab-runner/certs/newgitlab.com.crt"

三、运行gitlab job示例说明
1.1 打开测试仓库的Pipeline editor,截图如下

1.2 编辑.gitlab-ci.yml文件内容,.gitlab-ci.yml内容如下,点击Commit changes按钮即可运行gitlab job
# This file is a template, and might need editing before it works on your project.
# This is a sample GitLab CI/CD configuration file that should run without any modifications.
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
# it uses echo commands to simulate the pipeline execution.
#
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
# Stages run in sequential order, but jobs within stages run in parallel.
#
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages
#
# You can copy and paste this template into a new `.gitlab-ci.yml` file.
# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword.
#
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml

stages:          # List of stages for jobs, and their order of execution
  - build
  # - test
  # - deploy
  - release

build-job:       # This job runs in the build stage, which runs first
  stage: build
  tags: # 可以运行此项任务的Runner tag 筛选
    - gitlab-release-ci # Runner的tag名
  script:
    - echo "Compiling the code..."
    - echo "Compile complete."

# unit-test-job:   # This job runs in the test stage.
#   stage: test    # It only starts when the job in the build stage completes successfully.
#   tags: # 可以运行此项任务的Runner tag 筛选
#     - gitlab-release-ci # Runner的tag名
#   script:
#     - echo "Running unit tests... This will take about 60 seconds."
#     #- sleep 60
#     - echo "Code coverage is 90%"

# lint-test-job:   # This job also runs in the test stage.
#   stage: test    # It can run at the same time as unit-test-job (in parallel).
#   tags: # 可以运行此项任务的Runner tag 筛选
#     - gitlab-release-ci # Runner的tag名
#   script:
#     - echo "Linting code... This will take about 10 seconds."
#     #- sleep 10
#     - echo "No lint issues found."

# deploy-job:      # This job runs in the deploy stage.
#   stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.
#   tags: # 可以运行此项任务的Runner tag 筛选
#     - gitlab-release-ci # Runner的tag名
#   environment: production
#   script:
#     - echo "Deploying application..."
#     - echo "Application successfully deployed."

#将已有的二进制连接自动打包到release版本中
release-job:
  stage: release  # It only runs when *both* jobs in the test stage complete successfully.
  tags: # 可以运行此项任务的Runner tag 筛选
    - gitlab-release-ci # Runner的tag名
  rules:
    - if: $CI_COMMIT_TAG                 # Run this job when a tag is created  即创建新的tag
  environment: production
  script:
    - echo "running release_job"
  release:                               # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties
    tag_name: '$CI_COMMIT_TAG'
    description: '$CI_COMMIT_TAG'
    assets:
      links:
        - name: 'rabbitmq_delayed_message_exchange-3.12.0.ez'
          url: 'https://newgitlab.com/gitlab-instance-85cd3587/repository/-/raw/main/rabbitmq/rabbitmq_delayed_message_exchange-3.12.0.ez?inline=false'
          filepath: '/rabbitmq/rabbitmq_delayed_message_exchange-3.12.0.ez'
          link_type: 'other'
    

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
GitLab RunnerGitLab CI/CD的执行代理,用于运行作业和管道。在这里提供GitLab Runner安装和使用方法。 1. 安装GitLab Runner - Ubuntu/Debian系统 ``` # 安装依赖 sudo apt-get update sudo apt-get install -y curl # 安装GitLab Runner curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash sudo apt-get install gitlab-runner ``` - CentOS/RHEL系统 ``` # 安装依赖 sudo yum install -y curl policycoreutils-python openssh-server # 安装GitLab Runner curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash sudo yum install gitlab-runner ``` 2. 注册GitLab Runner - 打开GitLab网站,进入Settings -> CI/CD -> Runners页面,获取注册命令。 - 执行注册命令,输入GitLab网站的URL和注册令牌。 ``` sudo gitlab-runner register ``` 3. 编写.gitlab-ci.yml文件 - 在GitLab项目的根目录下创建.gitlab-ci.yml文件。 - 编写作业和管道。 ``` stages: - build - test - deploy build: stage: build script: - echo "Build" test: stage: test script: - echo "Test" deploy: stage: deploy script: - echo "Deploy" ``` 4. 提交代码并触发管道 - 将.gitlab-ci.yml文件提交到GitLab仓库。 - 在GitLab网站上进入项目的Pipelines页面,点击"Run Pipeline"按钮,即可触发管道。 5. 查看管道结果 - 在GitLab网站上进入项目的Pipelines页面,可以查看管道的执行结果。 - 如果管道执行失败,可以点击"Retry"按钮重新执行管道。 以上就是GitLab Runner安装和使用方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值