使用 Jenkins 管道脚本从 Windows 到 Linux 的 SCP [英] SCP from Windows to Linux using Jenkins pipeline script

查看:38
本文介绍了使用 Jenkins 管道脚本从 Windows 到 Linux 的 SCP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做 SCP 从 Windows Jenkins 节点到 Linux 服务器.在此设置中,Windows 机器是 Jenkins 从机,而我要复制的目标服务器是 Linux.

I want to do SCP from Windows Jenkins node to Linux server. In this set up, Windows machine is a Jenkins slave and the target server where i want to copy is Linux.

下面是我的 Jenkins 流水线脚本.在下面的脚本运行之前,我正在克隆存储库,然后构建项目,最终创建一个 .jar 文件.我想将此文件复制到 Linux 服务器.

Below is my Jenkins pipeline script. Before the below script runs, i am cloning the repository and then building the project which finally creates a .jar file. I want to copy this file to Linux server.

stage('SCP JAR file') {
    steps {
             bat 'scp /c/Jenkins/workspace/migration/test-project/build/libs/ssupservice-0.0.1-SNAPSHOT.jar rxp096p@server:/home/rxp096p/testing'
          }
     }
}

我的工作目录是 /c/Jenkins/workspace/migration/test-project/.在给定目录中,build/libs 文件夹会在所需的 .jar 文件所在的位置创建.

My working directory is /c/Jenkins/workspace/migration/test-project/. Inside the given directory, build/libs folder gets created where the required .jar file is present.

运行上面的脚本会出现以下错误:

Running above script gives the following error:

/c/Jenkins/workspace/migration/test-project/build/libs/ssupservice-0.0.1-SNAPSHOT.jar: No such file or directory

推荐答案

试一试:

pipeline {
    agent any

    stages {
        stage('SCP JAR file') {
            steps {
                bat '"c:\Program Files\git\usr\bin\scp.exe" -i "c:\Users\tom\.ssh\azure\id_rsa" C:\Users\tom\.jenkins\workspace\scp-to-linux\abc.jar tom@xy.xyz.xy.xz:abc.jar'
                bat '"c:\Program Files\git\usr\bin\ssh.exe" -i "c:\Users\tom\.ssh\azure\id_rsa" tom@xy.xyz.xy.xz ls -ltr'
            }
        }
    }
}

注意:在执行scp时,如果你不指定destination文件名,它会在远程服务器上创建文件完整的源路径名称.例如,在我的情况下,如果我没有指定,它会在远程服务器上创建名为 C:Users om.jenkinsworkspacescp-to-linuxabc.jar 的文件这个语法:tom@xy.xyz.xy.xz:abc.jar

Note: While doing scp, if you do not specify the destination file name, it will create file on remote server with the complete source path name. For example, in my case, it would have created file with the name C:Users om.jenkinsworkspacescp-to-linuxabc.jar on remote server had i not specified this syntax: tom@xy.xyz.xy.xz:abc.jar

这篇关于使用 Jenkins 管道脚本从 Windows 到 Linux 的 SCP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆