自托管github运行程序不会在LABEL上执行操作



我想学习如何使用带有标签的自托管github运行器。我在服务器上安装了一个自托管github运行器,并将其命名为prj1。然后我做了一个github项目,并包含了这个.github/workflows/deploy.yml文件。

name: Environment
on:
push:
branches:
- master
jobs:
p1:
runs-on: self-hosted
steps:
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event." >> deploy-log.txt

当我推送到主分支时,我的自托管github运行程序显示SUCCESS。这是目前为止最完美的。

然后我改变了我的.github/workflows/deploy.yml,包括这样的标签:

name: Environment
on:
push:
types: [prj1]
branches:
- master
jobs:
p1:
runs-on: self-hosted
steps:
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event." >> deploy-log.txt

然后我推到了master。但是github运行程序没有显示任何迹象表明它检测到任何东西。github网站的动作显示"此检查被跳过"。然后我尝试了这个:

name: Environment
on:
push:
branches:
- master
jobs:
p1:
if: ${{ github.event.label.name == 'prj1' }}
runs-on: self-hosted
steps:
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event." >> deploy-log.txt

同样,当我将更改推送到master时,git hub运行器没有显示任何它检测到任何东西的迹象。github网站操作提示"此检查被跳过"。

如何让我的自托管运行程序仅在标签为prj1的作业上部署项目?

找到答案:https://docs.github.com/en/actions/hosting-your-own-runners/using-self-hosted-runners-in-a-workflow#using-custom-labels-to-route-jobs

基本上我可以使用runs-on来指定哪个标签。所以我的yml文件现在看起来像这样

name: Environment
on:
push:
branches:
- master
jobs:
p1:
runs-on: prj1
steps:
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event." >> deploy-log.txt

这意味着在带有prj1标记的自托管github运行程序上将运行该作业。

最新更新