如何根据不同的运行器跳过 gitlab-ci.yml 中的作业?
我使用 gitlab 作为我的 CI/CD 系统。我需要设置我自己的跑步者。 我有两个跑步者,分别是带有“powershell”的“windows”和带有“shell”的“macos”。我希望他们中的任何一个都可以运行我的构建工作。 “macos”是一台笔记本电脑,因此它并不总是在线。因此,我编写了两个版本的构建作业,并希望为不同的运行器执行其中之一。
当我使用运行者标签时,这两个作业都会执行。并且构建将执行两次。如果我的“macos”离线,build-mac
将卡住。
build-win:
stage: build
tags:
- windows
script: powershell command...
build-mac:
stage: build
tags:
- macos
script: shell command...
所以我认为我需要“跳过”这份工作,但不选择跑步者。所以我尝试使用 only
或 rules
来跳过该作业。我找到链接: https://gitlab.com/gitlab-org/gitlab //问题/21860 但正如问题所述,CI_RUNNER_EXECUTABLE_ARCH
不能在 only
、except
和 rules
中使用。
build-win:
stage: build
script: powershell command...
rules:
- if: $CI_RUNNER_EXECUTABLE_ARCH =~ /^windows.*/
build-mac:
stage: build
script: shell command...
rules:
- if: $CI_RUNNER_EXECUTABLE_ARCH =~ /^(darwin|linux).*/
我认为这两种解决方案都不合适。有没有更好的方法来做到这一点? 谢谢~
I am using the gitlab as my CI/CD system. And I need setup my own runner.
I have two runner both 'windows' with 'powershell' and 'macos' with 'shell'. I want either of them can run my build job. The 'macos' is a laptop so it not always online. So I write two version of build jobs, and hope just execute one of them for different runner.
When I use the runner tags, both of the job will execute. And the build will execute twice. If my 'macos' is offline, the build-mac
will stuck.
build-win:
stage: build
tags:
- windows
script: powershell command...
build-mac:
stage: build
tags:
- macos
script: shell command...
So I think I need 'skip' the job but not select a runner. So I am trying to use only
or rules
to skip the job. I find the linkage: https://gitlab.com/gitlab-org/gitlab/-/issues/21860
But as the issues said, the CI_RUNNER_EXECUTABLE_ARCH
can not use in only
, except
and rules
.
build-win:
stage: build
script: powershell command...
rules:
- if: $CI_RUNNER_EXECUTABLE_ARCH =~ /^windows.*/
build-mac:
stage: build
script: shell command...
rules:
- if: $CI_RUNNER_EXECUTABLE_ARCH =~ /^(darwin|linux).*/
I think both of the solution is not suitable. Is there any better way to do this?
Thank you~
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在预定义变量中没有看到任何选项,例如跑步者在线状态。
如果您想根据跑步者状态建立跑步规则,您可能必须利用个人令牌(或者可能是项目令牌)来访问跑步者 api 来获取状态。你可以这样做:
Not seeing any options in predefined variables for anything like runner online status.
If you want to base a run rule by runner status, you will probably have to leverage a personal token (or maybe a project token) to hit the runners api for status. You could do something like this:
您可以使用 $CI_RUNNER_TAGS 或 $CI_RUNNER_ID 预定义变量。
示例:
或:
You can use the $CI_RUNNER_TAGS or $CI_RUNNER_ID predefined variables.
Example:
Or: