참고

AWS EC2 보안그룹 설정

플러그인 설치

Credential 설정

파이프라인 설정 예시

pipeline {
    agent any

    stages {

        stage('Deploy') {
            steps {
                script {
                    withCredentials([
                            sshUserPrivateKey(credentialsId: 'mysshkey', keyFileVariable: 'identity', usernameVariable: 'userName')
                    ]) {

                        def remote = [:]
                        remote.name = "ssh-target"
                        remote.host = "192.168.123.456"
                        remote.allowAnyHosts = true
                        remote.user = userName
                        remote.identityFile = identity

                        stage("Hello") {
                            sshCommand remote: remote, command: 'cd ~ && echo > jenkins.success'
                        }

                        stage("Git Pull") {
                            sshCommand remote: remote, command: 'cd ~/repo && git pull'
                        }
                    }
                }
            }
        }

    }
}