如何使用SSH密钥将角度生成版本部署到使用bitbucket管道的外部服务器?

问题描述 投票:0回答:3

我们正在尝试使用Bitbucket Pipelines将基本角度应用程序部署到Google Cloud上的VM,但不确定如何使用SSH密钥连接到服务器以复制构建文件。寻找例子但找不到。

我们能够使用Putty / SSH命令手动复制dist文件。

我们拥有Google Cloud VM的公钥/私钥,并将其添加到Bitbucket Pipelines> SSH Keys

enter image description here

我们的YML脚本如下:

image: node:6.9.4

pipelines:
  default:
    - step:
       caches:
         - node
       script: # Modify the commands below to build your repository.
         - npm install
         - npm install -g @angular/[email protected]
         - ng build --prod
         - cd dist/
         - ssh -i ???
angular bitbucket-pipelines
3个回答
1
投票

正如@Chris所说,that article是正确的起点。步骤是:

  1. 通过UI或运行ssh-keygen在BitBucket中添加SSH密钥
  2. 通过UI更新已知主机。
  3. 通过将公钥添加到远程主机 cat ~/.ssh/my_ssh_key.pub | ssh username@remote_host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"

或通过

`ssh-copy-id -i my_ssh_key username@remote_host`
  1. 然后使用此命令复制文件(应该在您的脚本中): scp username@remote_host:/path/to/file /path/to/destination

0
投票

相当肯定this tutorial可能会派上用场


0
投票

我们能够解决这个问题如下:

  1. 在Bitbucket>项目源存储库>设置>管道> SSH密钥下 添加私钥和公钥 添加已知主机(这将是您要将代码推送到的服务器的IP地址。在我们的示例中,这是Google Cloud上的VM)
  2. 更新您的脚本如下: image: node:8 pipelines: default: - step: caches: - node script: # Modify the commands below to build your repository. #- echo "$(ls -la)" - npm install - npm install -g @angular/cli - ng build --prod - echo "$(ls -la dist/)" - scp -r dist/ [email protected]:/home/suren/temp
© www.soinside.com 2019 - 2024. All rights reserved.