【问题标题】:Azure pipeline connect to an ssh server and then copy files into itAzure 管道连接到 ssh 服务器,然后将文件复制到其中
【发布时间】:2021-08-26 13:02:53
【问题描述】:

我实际上是在尝试使用 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。

【问题讨论】:

    标签: ssh azure-devops yaml azure-pipelines


    【解决方案1】:

    公钥存储在您的远程计算机上。您需要将私钥上传到您的 SSH 服务连接(导航 Project settings > Service connections

    之后,您可以使用 Copy files over 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

    【讨论】:

    • 感谢您的回答。我试过这种方式,但我无法建立 ssh 连接。我必须从预览功能中禁用新服务连接?
    猜你喜欢
    • 2019-05-30
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 2018-12-03
    • 2022-11-28
    • 1970-01-01
    • 2020-05-01
    • 1970-01-01
    相关资源
    最近更新 更多