vue.js - 如何在 gitlab Ci/CD 中运行远程命令?
问题描述
我有以下 .gitlab-ci.yml 文件,用于托管在 gitlab.com 上的 gitlab 存储库,以使用 gitlab CI/CD 构建和部署 vue 应用程序:
image: node:latest
cache:
paths:
- node_modules/
before_script:
- apt-get update -qq && apt-get install -y -qq sshpass
build_deploy_stage:
stage: build
environment: Staging
only:
- master
script:
- rm ./package-lock.json
- npm install
- node -v
- npm run build
- ls
- sshpass -V
- export SSHPASS=$USER_PASS
- sshpass -e scp -o stricthostkeychecking=no -r dist user@example.com:~/myapp
部署后,我想像远程登录一样在命令下运行 (ssh user@example.com):
$ pm2 重启 myapp
$ cp ~/myfiles/file1 ~/backup/myfiles/file1.bk
如何将上述命令添加到 .gitlab-ci.yml ?
推荐的方法是使用带有公钥的 ssh 而不是 sshpass。使用 ssh 密钥对并登录远程主机(example.com)并从 gitlab CI/CD 运行器中在远程主机上运行命令的解决方案是什么?
解决方案
推荐阅读
- mysql - SQL - 从星期一到星期日按工作日排序 DATE_FORMAT
- python - 使用平均阈值过滤 DataFrame
- java - 如何使用java中的构造函数返回一个类?
- javascript - 检查具有属性的数组对象是否存在的最佳方法是什么?
- pandas - 如何从 DataFrame.groupby.rolling.apply 返回多个值?
- java - 用 Java 解析一个简单的 HTML
- android - 如何使用通过 Retrofit Kotlin 编码的表单 URL 发送对象数组?
- c# - 图像从视图中变为空
- compiler-errors - VHDL 错误(10482)对象 std_logic_vector 已使用但未声明
- google-cloud-firestore - 使用 Cloud Datastore 而不是 Cloud Firestore 的真正好处是什么?