外部服务器上的gitlab CI / CD运行命令

时间:2019-04-16 08:34:32

标签: gitlab

我想使用gitlabs CI / CD在外部服务器上部署我的应用程序。我有IP,用户名和密码,我知道我需要通过SSH连接。我如何在服务器端运行所有必要的命令。服务器在Linux上运行。

目前,我只是从reposiroty获取代码,然后将其代码传递给npm build:prod和npm serve:prod用于API,npm start用于UI。我该如何使用gitlab CI / CD做相同的摄录机链?还是有可能吗?我基本上希望它像詹金斯作品一样运行。但是由于代码已经在gitlab上了,所以让gitlab来处理此过程而不是安装和设置jenkins可能会更简单。

1 个答案:

答案 0 :(得分:0)

To be able to SSH to your machine from within GitLab CI, you probably should setup ssh key authentication, since you can't just type in the password inside the CI.

When you've got that set up, you have to store the private key in an environment variable so you can use it in the CI job. How to do that can be found here.

The last part is actually executing commands over ssh. That can be done in the following way:

ssh <host> '
    command1;
    command2;
'