Reputation: 1972
I have tried multiple solutions in jenkins to copy a file on remote which is EC2 window server on AWS.
Publish over ssh: provided key, hostname, username and password but connection is failed every time
pipeline script:
pipeline { agent any
stages {
stage('SCP') {
steps {
bat '"C:\\Program Files\\Git\\usr\\bin\\scp.exe" -i "C:\\Live" C:\\Windows\\System32\\config\\systemprofile\\AppData\\Local\\Jenkins\\.jenkins\\workspace\\MSDeploy\\abc.txt abc.txt'
bat '"c:\\Program Files\\Git\\usr\\bin\\ssh.exe" -i "C:\\Live" [email protected] ls -ltr'
}
}
}
}
where C:\Live
is remote server directory and C:\\Windows\\System32\\config\\systemprofile\\AppData\\Local\\Jenkins\\.jenkins\\workspace\\MSDeploy\\abc.txt
is the local directory, but it throws an error: shows no such file or directory found
pipeline {
agent any
stage ('Deploy') {
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'var', credentialsId: 'credid', secretKeyVariable: 'seckey']]) {
writeFile file: 'groovy1.txt', text: 'ls'
bat 'ls -l groovy1.txt'
bat 'cat groovy1.txt'
}
}
}
}
It does create file with text but doesn't work. None of the solutions worked for me.
What I have missed?
Upvotes: 0
Views: 9079
Reputation: 2140
You're using windows server, you need to use some tools to achieve this, copy over ssh probably won't work here. The best straight solution which I normally use it.
Step 1:
net use N: \\ServerName\Folder /user:Administrator Password
N is your drive
copy "D:\Jenkins\file N:"
You can use these commands in your jenkins file refer this link for the same https://thenucleargeeks.com/2020/11/24/how-to-run-batch-scripts-commands-in-jenkinsfile/ This will work for your case, let me know if you face any issue.
Upvotes: 0