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('部署到 K8s') {
steps {
echo '部署中...'
script {
withKubeConfig([credentialsId: 'f23cc59c-dfd1-40b9-a12f-2c9b6909e908']) {
sh(script: "kubectl create secret docker-registry coding --docker-server=${dockerServer} --docker-username=${env.DOCKER_USER} --docker-password=${env.DOCKER_PASSWORD} --docker-email=support@coding.net", returnStatus: true)
sh "kubectl patch deployment laravel-demo --patch '{\\"spec\\": {\\"template\\": {\\"spec\\": {\\"containers\\": [{\\"name\\": \\"web\\", \\"image\\": \\"${imageName}\\"}], \\"imagePullSecrets\\": [{\\"name\\": \\"coding\\"}]}}}}'"
}
}
}
}
}
}
本页内容是否解决了您的问题?