cyywl_server/builds/Jenkinsfile

45 lines
2.1 KiB
Groovy

pipeline {
agent any
environment {
INTRANET_REGISTRY='192.168.1.124:10083'
PUBLIC_REGISTRY='192.168.1.124:10083'
IMAGE_NAMESPACE='cmx'
IMAGE_NAME='yudao-server-api'
GIT_BRANCH='feature/mall_product'
Dockerfile='builds/Dockerfile'
DockerComposefile='docker-compose-test.yml'
}
stages {
stage('Pull Code') {
steps {
checkout([$class: 'GitSCM', branches: [[name: "$GIT_BRANCH"]], extensions: [cloneOption(depth: 1, noTags: true, reference: '', shallow: true)], userRemoteConfigs: [[credentialsId: 'Hx-Deploy-Git', url: 'http://117.33.142.185:3000/zenghuapei/cyywl_server.git']]])
}
}
stage('compile & buildImage->push') {
steps {
withMaven(maven: 'M3') {
sh 'mvn clean package -Dmaven.test.skip=true'
}
withCredentials([usernamePassword(credentialsId: 'HxDockerRepo', passwordVariable: 'DOCKER_PASSWORD', usernameVariable: 'DOCKER_USERNAME')]) {
sh 'docker build -f $Dockerfile -t $INTRANET_REGISTRY/$IMAGE_NAMESPACE/$IMAGE_NAME:$BUILD_ID .'
sh 'echo "push start..."'
sh 'docker push $INTRANET_REGISTRY/$IMAGE_NAMESPACE/$IMAGE_NAME:$BUILD_ID'
}
}
}
stage('SSH Deploy') {
steps {
withCredentials([sshUserPrivateKey(credentialsId: 'halo-test-ssh', keyFileVariable: 'primaryKeyVar', usernameVariable: 'userVar')]) {
sh 'ssh -i ${primaryKeyVar} root@36.41.184.13 "curl -s https://cmx.bskies.cc:8000/shell/deploy/init_work_dir.sh | bash -s /opt/app/${IMAGE_NAME}"'
sh 'scp -i ${primaryKeyVar} builds/${DockerComposefile} root@36.41.184.13:/opt/app/${IMAGE_NAME}'
sh 'ssh -i ${primaryKeyVar} root@36.41.184.13 "curl -s https://cmx.bskies.cc:8000/shell/deploy/docker_deploy.sh | bash -s /opt/app/${IMAGE_NAME} $PUBLIC_REGISTRY/$IMAGE_NAMESPACE/$IMAGE_NAME:$BUILD_ID /opt/app/${IMAGE_NAME}/$DockerComposefile"'
}
}
}
}
}