繁体   English   中英

如何使用 Jenkins 管道将文件从 Github 克隆到 VM?

[英]How to clone files from Github to VM using Jenkins pipeline?

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

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

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

因此,首先我应该将这个 repo 克隆到我的代理(192.168.10.10 '/var/lib/jenkins/workspace/'),然后从那里复制到我的 VM?

它看起来像

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

进而?

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

看起来您正在使用两台 Linux 服务器。 在复制文件之前,请确保您的 Jenkins 服务器可以访问您要将文件复制到的虚拟机。 如果不按照这个 [ssh between two servers][1] 提供对 Jenkins 服务器的访问

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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM