如何使用Jenkins将Docker映像部署到AWS

时间:2020-02-04 10:42:41

标签: docker amazon-ec2 jenkins-pipeline

我是Jenkins的新手,正在尝试使部署系统自动化,我在React App中创建了Jenkins和Docker文件,将Git链接到Jenkins,将DockerHub链接到Jenkins。 一切正常,只有部署部分不起作用。 詹金斯档案:-

node {
    stage("Checkout"){
        checkout scm
    }
}
pipeline{
    agent any
    stages{
        stage("Build Image"){
            steps {
                echo 'Starting to build docker image'
                script {
                    def app = docker.build("totodocker/totosuite_fe")
                    docker.withRegistry('https://registry.hub.docker.com/', 'hub_credentials') {
                        app.push("${BUILD_NUMBER}")
                    }
                }
            }
        }
        stage("Deploy"){
            steps{
                withCredentials(['ssh-server-credentials']) {
                    script {
                        def remote = [:]
                        remote.name = 'dev server'
                        remote.host = 'serve_ip'
                        remote.user = 'ubuntu'
                        remote.allowAnyHosts = true
                    }
                }
                   sshagent(credentials: ['ssh-server-credentials']) {
                       echo "branch name = ${BRANCH_NAME}"
                       sh 'ssh ubuntu @server_ip'
                       docker.withRegistry('https://registry.hub.docker.com/', 'hub_credentials') {
                           sh 'docker pull totodocker/totosuite_fe:${BUILD_NUMBER}'
                           sh 'docker run -p 3000:3000 totodocker/totosuite_fe:${BUILD_NUMBER}'
                           echo "docker container started"
                       }
                   }
            }
        }
    }
    post{
        success{
            echo "========pipeline executed successfully ========"
        }
        failure{
            echo "========pipeline execution failed========"
        }
    }
}

我遇到以下错误: 找不到SSH代理。

0 个答案:

没有答案