首页 > 解决方案 > 如何使用 Jenkins 管道将文件从 Github 克隆到 VM?

问题描述

我已经开始学习 Jenkins,这是一个入门任务)。

我在 GitHub 上有一个小网站(html 和 css 文件)和一个 Linux 服务器(虚拟机)。如何将文件从 git 克隆到“/var/www/”文件夹中的虚拟机。

例如:Jenkins 服务器在 192.168.10.10 上运行,目标虚拟机在 192.168.2.30 上。

所以,首先我应该将此存储库克隆到我的代理(192.168.10.10 '/var/lib/jenkins/workspace/'),然后从那里复制到我的虚拟机?

它看起来像

pipeline {
  agent any
  
  stage ('Clone the git project'){
      step{
      git 'https://github.com/my_prod’
    }
 }
}

接着?

我已阅读文档,但无法理解如何正确执行。

标签: gitjenkinsjenkins-pipelinedevops

解决方案


Looks like you are using both Linux servers. Before copying the files make sure your Jenkins server has access to the vm that you're copying files to. If not follow this [ssh between two servers][1] to provide the access to the Jenkins server

pipeline {
  agent any
  
  stage ('Clone the git project'){
      step{
      git 'https://github.com/my_prod’
      script{
        scp user1@remote1:/home/user1/file1.txt user2@remote2:/home/user2/file1.txt
        }
    }
 }
}


  [1]: https://www.techrepublic.com/article/how-to-copy-a-file-between-two-remote-ssh-servers/

推荐阅读