Reputation: 466
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.
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'
}
}
}
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
Upvotes: 1
Views: 4233
Reputation: 8107
Give this a shot:
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 [email protected]:abc.jar'
bat '"c:\\Program Files\\git\\usr\\bin\\ssh.exe" -i "c:\\Users\\tom\\.ssh\\azure\\id_rsa" [email protected] ls -ltr'
}
}
}
}
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: [email protected]:abc.jar
Upvotes: 2