copy file from git repo to remote server with jenkins groovy
- User
copy file from git repo to remote server with jenkins groovy
- Assistant
To copy a file from a Git repository to a remote server using Jenkins Groovy, you can use the following script:
node { stage('Checkout') { // Checkout the Git repository git url: 'https://github.com/your-repo.git', branch: 'master' } stage('Copy file') { // Copy the file to the remote server sh 'scp file.txt user@remote-server:/path/to/destination' } }In this script, the Git repository is first checked out using the
gitstep in theCheckoutstage. Replace'your-repo.git'with the URL of your Git repository and'master'with the branch you want to checkout.In the
Copy filestage, theshstep is used to execute the shell commandscpto copy the filefile.txtto the remote server. Replace'file.txt'with the name of the file you want to copy and'user@remote-server:/path/to/destination'with the SSH login credentials and the destination path on the remote server.You can also add error handling and additional stages as per your requirements.