Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

copy file from git repo to remote server with jenkins groovy

  1. User

    copy file from git repo to remote server with jenkins groovy

  2. 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 git step in the Checkout stage. Replace 'your-repo.git' with the URL of your Git repository and 'master' with the branch you want to checkout.

    In the Copy file stage, the sh step is used to execute the shell command scp to copy the file file.txt to 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.