pipeline {
agent any
stages {
stage('检出') {
steps {
checkout([$class: 'GitSCM', branches: [[name: env.GIT_BUILD_REF]],
userRemoteConfigs: [[url: env.GIT_REPO_URL, credentialsId: env.CREDENTIALS_ID]]])
}
}
stage('构建') {
steps {
echo '构建中...'
script {
dockerServer = 'codes-farm-docker.pkg.coding.net'
dockerPath = '/laravel-demo/laravel-docker'
imageName = "${dockerServer}${dockerPath}/laravel-demo:1.0.0"
def customImage = docker.build(imageName)
docker.withRegistry("https://${dockerServer}", CODING_ARTIFACTS_CREDENTIALS_ID) {
customImage.push()
}
}
}
}
stage('部署') {
steps {
echo '部署中...'
script {
def remote = [:]
remote.name = 'web-server'
remote.allowAnyHosts = true
remote.host = '106.54.86.239'
remote.port = 22
remote.user = 'ubuntu'
withCredentials([sshUserPrivateKey(credentialsId: "c4af855d-402a-4f38-9c83-f6226ae3441c", keyFileVariable: 'id_rsa')]) {
remote.identityFile = id_rsa
sshCommand remote: remote, sudo: true, command: "apt-get install -y gnupg2 pass"
sshCommand remote: remote, command: "docker login -u ${env.DOCKER_USER} -p ${env.DOCKER_PASSWORD} $DOCKER_SERVER"
sshCommand remote: remote, command: "docker pull ${imageName}"
sshCommand remote: remote, command: "docker stop web | true"
sshCommand remote: remote, command: "docker rm web | true"
sshCommand remote: remote, command: "docker run --name web -d ${imageName}"
}
}
}
}
}
}
本页内容是否解决了您的问题?