如何正确使用GitLab Runner?

huangapple go评论60阅读模式
英文:

How to use gitlab runner correctly?

问题

我尝试弄清楚如何使用GitLab CI/CD流水线部署项目。
我创建了一个Runner,并在远程服务器上注册了它。之后,我尝试在.yml文件中实现一个简单的脚本:

 - whoami
 - echo "123" > 123.txt

在作业信息中,我看到whoami输出了错误的用户(root而不是ubuntu),而且文件也没有被创建。

更重要的是,存储库如何知道我要使用确切的Runner,我创建了哪个?我找不到任何相关信息。我理解我必须将我的存储库与我的Runner绑定,否则所有存储库都将使用相同的Runner!

英文:

I try to figure out how to deploy a project with gitlab ci-cd pipelines.
I created a runner, registered him on the remote server. After that, I am trying to implement a simple script in the .yml:

 - whoami
 - echo "123" > 123.txt

In the job info, I see that whoami out to me wrong user (root instead ubuntu), and also file isn't created.

More of then - how does the repository know that I want to use exactly that runner I created? I can't find any information about it. As I understand I have to bind my repository with my runner, in another way.....all repositories will use the same runner!

答案1

得分: 1

在GitLab中,您应该能够以两种方式将运行程序附加到项目中;
要么您为项目注册特定的运行程序,要么您启用共享运行程序(您应该能够在项目设置 > CICD > 运行程序下看到这两个类别的列表)

如果在那里看不到任何可用的运行程序,可能是您配置了运行程序错误。

要选择特定的运行程序,您可以使用运行程序的“标签”。

您可以为流水线设置默认值,并且还可以为各个阶段设置特定的标签。

以下是如何为默认值设置的示例:

default:
  tags:
    - backend-runner
英文:

In gitlab, you should be able to attach runners in 2 ways to a project;
either you register a runners specific to the project or you enable shared runners (you should be able to see the list of both categories under project setting > CICD > Runners)

If you don't see any available runners in there, you may be configuring the runners wrong.

To select a specific runner, you can use the 'tag' of the runner.

you can either set a default for the pipeline and have stage specifc too.

here is how you would do for default

 default:
  tags:
    - backend-runner

huangapple
  • 本文由 发表于 2023年6月29日 04:30:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76576524.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定