我实际上是在尝试使用 Azure DevOps 管道通过 ssh 将文件发送到外部服务器。
首先,我上传了我用来连接到该文档后的服务器的私钥:Secure file。
然后,我就跟那个文档 Install SSH keys 一样。
然后,我运行一个 node.js 项目来提取 dist 文件。
最后,我想使用 SSH 将我的 dist 文件复制到服务器中,就像这个文档解释它Copy Files Over SSH task。
trigger:
- main
pool:
vmImage: ubuntu-latest
steps:
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
cd front-react
npm install
npm run build
displayName: 'npm install and build'
# Install SSH key
# Install an SSH key prior to a build or deployment
- task: InstallSSHKey@0
name: localssh
inputs:
knownHostsEntry: 'xxx@1.1.1.1'
sshPublicKey: $(id_rsa)
sshKeySecureFile: privkey_file
- task: CopyFilesOverSSH@0
inputs:
sshEndpoint: localssh
contents: 'front-react/build/'
targetFolder: '/testssh'
readyTimeout: '20000'
问题是我不知道如何将 SSH 连接用于 sshEndpoint 属性。
这与这篇文章 How to use public key in azure devops pipline copy files over SSH 有关,但它没有明确说明如何使用该连接链接已安装的 ssh 和复制 ssh。
答案 0 :(得分:0)
公钥存储在您的远程机器上。您需要将私钥上传到您的 SSH 服务连接。
之后,您可以使用通过 SSH 复制文件任务来复制文件:
- task: CopyFilesOverSSH@0
displayName: 'Securely copy files to the remote machine'
inputs:
sshEndpoint: test
sourceFolder: '$(Build.SourcesDirectory)'
targetFolder: /home/azureuser/test
cleanTargetFolder: true
failOnEmptySource: true
请注意:我没有使用安装 SSH 密钥任务,而是使用了自托管代理。它对我有用。如果您想使用安装 SSH 密钥任务,请参考this document。