SCP from Windows to Linux using Jenkins pipeline script

后端 未结 1 1901
不知归路
不知归路 2021-01-16 09:07

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 Lin

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 09:46

    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 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'
                }
            }
        }
    }
    

    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

    0 讨论(0)
提交回复
热议问题