GitHub Actions自托管Runner无法拾取任务的问题求助
问题描述
配置GitHub Actions时,使用runs-on: ubuntu-latest时CI流程完全正常,但改为runs-on: self-hosted后,任务一直处于等待状态,自托管Runner无法接收到任务。
我的CI/CD配置文件如下:
name: CI-CD on: push: branches: [ "develop" ] pull_request: branches: [ "develop" ] jobs: my-job: runs-on: ubuntu-latest defaults: run: working-directory: ./frontend strategy: matrix: node-version: [16.x] steps: - name: CHECK-OUT GIT REPOSITORY uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} cache: 'npm' cache-dependency-path: '**/package-lock.json' - name: INSTALL DEPENDENCIES run: npm ci - name: BUILDING APP run: npm run build --if-present #- name: TESTINT APP #- run: npm test - name: Build & push Docker image uses: mr-smithers-excellent/docker-build-push@v5 with: image: user/frontend tags: latest registry: docker.io dockerfile: frontend/Dockerfile username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }}
排查与解决步骤
- 确认自托管Runner状态:进入仓库
Settings→Actions→Runners,检查Runner是否处于Idle状态。若显示Offline,重启Runner服务,确保它能正常连接GitHub。 - 检查标签匹配:如果自托管Runner添加了自定义标签,需在
runs-on中指定对应标签,比如runs-on: [self-hosted, linux, x64]。默认自托管Runner带有self-hosted标签,但如果有其他限定标签,必须完全匹配才能触发任务。 - 验证Runner权限范围:确认自托管Runner是安装在当前仓库下,若为组织级Runner,需在仓库
Actions设置中开启允许使用组织Runner的权限。 - 检查Workflow权限:进入仓库
Settings→Actions→General,确认Workflow permissions设置为Read and write permissions,避免权限不足导致Runner无法接收任务。 - 查看Runner本地日志:在自托管Runner的运行终端查看日志,比如执行
./run.sh的输出,排查是否存在连接错误或认证失败的信息。 - 确认配置修改正确性:检查是否已将
runs-on: ubuntu-latest正确替换为runs-on: self-hosted(或带标签的格式),无拼写错误。
内容的提问来源于stack exchange,提问作者Sodiki
相关产品推荐
相关产品推荐

