使用Jenkins管道脚本从Windows到Linux的SCP [英] SCP from Windows to Linux using Jenkins pipeline script
问题描述
我想从Windows Jenkins节点到Linux服务器执行SCP
.在此设置中,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
时,如果未指定目的地文件名,它将在远程服务器上使用完整的源路径创建文件名称.例如,在我的情况下,如果我未指定以下语法,它将在远程服务器上创建名称为C:\Users\tom\.jenkins\workspace\scp-to-linux\abc.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\tom\.jenkins\workspace\scp-to-linux\abc.jar
on remote server had i not specified this syntax: tom@xy.xyz.xy.xz:abc.jar
这篇关于使用Jenkins管道脚本从Windows到Linux的SCP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!