首页 > 解决方案 > Github actions 如何在两台服务器上配置两个运行器

问题描述

在此处输入图像描述

我有一个名为api. api有两个分支DEVQA

DEV我已经为分支设置了工作流程并且工作正常。

这是DEV分支的工作流程

# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
  push:
    branches: [DEV]
  pull_request:
    branches: [DEV]

jobs:
  build:
    runs-on: self-hosted
    strategy:
      matrix:
        node-version: [14.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
          cache: "npm"
      - run: npm ci
      # - run: pm2 stop app.js
      - run: pm2 start ecosystem.config.js --update-env

然后我创建了我的第二个 EC2 实例和第二个运行器以及另一个工作流文件

# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: QA Build

on:
  push:
    branches: [ QA ]
  pull_request:
    branches: [ QA ]

jobs:
  build:

    runs-on: self-hosted
    strategy:
      matrix:
        node-version: [14.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
    - run: npm i
    - run: pm2 start ecosystem.config.js --update-env

但是每当我将一些代码推送到QA分支时,我的第一个跑步者仍然会运行并且第一个 EC-2 实例。似乎第二个实例或工作流根本不使用。如何根据分支指定运行器和实例?

标签: githubgithub-actionscicd

解决方案


如果您只有两个使用默认设置的跑步者,您将无法区分两者。因此,这样的工作只需要两者中的任何一个。

标签可以标记一个特定的跑步者,然后您可以直接选择。请参阅标签上的 GitHub 自托管运行器文档

然后您可以像这样使用特定的跑步者

runs-on: [self-hosted, dev]

推荐阅读