简体   繁体   English

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

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

I have started learn Jenkins and here is an entry task).我已经开始学习 Jenkins,这是一个入门任务)。

I have a small website on GitHub(html and css files) and a Linux server(virtual machine).我在 GitHub(html 和 css 文件)和 Linux 服务器(虚拟机)上有一个小网站。 How can I clone files from git to a virtual machine in a '/var/www/' folder.如何将文件从 git 克隆到“/var/www/”文件夹中的虚拟机。

For instance: Jenkins server running on 192.168.10.10, destination VM on 192.168.2.30.例如:Jenkins 服务器在 192.168.10.10 上运行,目标 VM 在 192.168.2.30 上。

So, at first I should clone this repo to my agent(192.168.10.10 '/var/lib/jenkins/workspace/') and from there copy to my VM?因此,首先我应该将这个 repo 克隆到我的代理(192.168.10.10 '/var/lib/jenkins/workspace/'),然后从那里复制到我的 VM?

It will look like它看起来像

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

And then?进而?

I've read documentation, but can't understand how to do it properly.我已阅读文档,但无法理解如何正确执行。

Looks like you are using both Linux servers.看起来您正在使用两台 Linux 服务器。 Before copying the files make sure your Jenkins server has access to the vm that you're copying files to.在复制文件之前,请确保您的 Jenkins 服务器可以访问您要将文件复制到的虚拟机。 If not follow this [ssh between two servers][1] to provide the access to the Jenkins server如果不按照这个 [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