【问题标题】:Github actions how to configure two runners in two serversGithub actions 如何在两台服务器上配置两个runner
【发布时间】:2021-08-10 02:58:12
【问题描述】:

我有一个名为 api 的 GitHub 存储库。 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 实例仍然运行。似乎第二个实例或工作流根本不使用。 如何根据分支指定runner和instance?

【问题讨论】:

    标签: github github-actions cicd


    【解决方案1】:

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

    标签可以标记一个特定的跑步者,然后您可以直接选择。见GitHub self-hosted runners docs on labels

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

    runs-on: [self-hosted, dev]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-26
      • 2020-08-13
      • 2017-08-30
      • 2012-09-04
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多