gitea流水线配置和调试(在宿主机上运行)
发表于:2026-10-28 17:37:05浏览:9次
下载安装
VERSION=5.2.0
curl -sSLO "https://dl.gitea.com/gitea-runner/$VERSION/gitea-runner-$VERSION-linux-amd64"
curl -sSLO "https://dl.gitea.com/gitea-runner/$VERSION/gitea-runner-$VERSION-linux-amd64.sha256"
sha256sum -c "gitea-runner-$VERSION-linux-amd64.sha256"
sudo install -m 0755 "gitea-runner-$VERSION-linux-amd64" /usr/local/bin/gitea-runner
将gitea-runner装入系统服务
vi /etc/systemd/system/gitea-runner.service
- 写入如下内容:(注意,这里的NVM安装Node的情况,若不是,可直接删除掉环境变量内Node相关内容,注意版本号)
[Unit]
Description=Gitea Actions runner
Documentation=https://gitea.com/gitea/runner
After=network-online.target
Wants=network-online.target
# Uncomment when jobs use the local Docker daemon:
# After=docker.service
# Requires=docker.service
[Service]
Type=simple
ExecStart=/usr/local/bin/gitea-runner daemon --config /etc/gitea-runner/config.yaml --labels ubuntu-latest:host
WorkingDirectory=/www/data/gitearunner/
User=root
Group=root
Restart=on-failure
RestartSec=5s
TimeoutStopSec=3h
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.nvm/versions/node/v22.23.4/bin"
[Install]
WantedBy=multi-user.target
写入配置文件至
/etc/gitea-runner/config.yaml先进入
/etc/gitea-runner文件夹,执行命令gitea-runner config init gitea-runner config set runner.capacity 4 gitea-runner config set runner.timeout 90m gitea-runner config set runner.envs.MY_VAR value gitea-runner config add container.valid_volumes '/data/**' gitea-runner config remove container.valid_volumes '/data/**'内容如下:
# Minimal config file. Every option it does not set keeps its default.
# "gitea-runner config generate" prints all options, "config set <key> <value>" sets one here.
runner:
capacity: 4
timeout: 1h30m0s
envs:
MY_VAR: value
labels:
- "ubuntu-latest:host"
container:
valid_volumes: []
- 启动服务
sudo systemctl daemon-reload service gitea-runner start
前置任务
- 安装Node,若使用NVM安装的话需要执行下述命令:(不是NVM安装可直接跳过)
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrcecho '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.bashrcecho '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> ~/.bashrcsource ~/.bashrc
注册服务(在运行目录下执行,目录下会生成两个文件.runner和.runer.lock)
gitea-runner register --no-interactive --instance <您的仓库地址> --token <token> --labels ubuntu-latest:host --name <运行器名称>
服务注册后,可修改runner
{ "WARNING": "This file is automatically generated by Gitea Runner. Do not edit it manually unless you know what you are doing. Removing this file will cause Gitea Runner to re-register as a new runner.", "id": 9, "uuid": "f1", "name": "test", "token": ".....", "address": "....", "labels": [ "ubuntu-latest:host" ], "ephemeral": false }此时,runner便运行在了宿主机上,更方便的解决运行环境等问题。
编写ci.yml文件(位于项目目录/.gitea\workflows\ci.yml)
- 示例文件
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
phpunit:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup environment
run: |
cp .env.example .env
echo "QUEUE_CONNECTION=sync" >> .env
- name: Run TESTUnit
run: go test
notify:
needs: phpunit
runs-on: ubuntu-latest
steps:
- name: Send webhook
run: curl -X GET https://www.itgz8.com/
