Browse Source

构建镜像稳定

wuheng 1 year ago
parent
commit
977e72f183
2 changed files with 5 additions and 5 deletions
  1. 4 4
      Jenkinsfile
  2. 1 1
      docker-compose.yml

+ 4 - 4
Jenkinsfile

@@ -13,12 +13,12 @@ pipeline {
         stage('Build') {
             steps {
                 echo 'Building..'
-
-                sh 'EASID=$(docker ps | grep easapimaster | awk \'{print $1}\')'
-                sh '[ -n "$EASID" ] && docker kill $EASID && docker rm $EASID || echo -n "Docker Container is Down!"'
+                sh 'EASID=$(docker ps | grep easapi${BRANCH_NAME} | awk \'{print $1}\')'
+                sh '[ -n "$EASID" ] && docker kill $EASID && docker rm $EASID || echo -n "Docker Container is Down"'
+                sh '[ -n "$EASID" ] && docker images | grep easapi${BRANCH_NAME} | awk \'{print $1":"$2}\' | xargs docker rmi || echo -n "No Images of remove"'
                 sh '~/tools/apache-maven-3.6.3/bin/mvn sonar:sonar'
                 sh '~/tools/apache-maven-3.6.3/bin/mvn  clean install -Dmaven.test.skip=true'
-                sh 'docker build -t ${BRANCH_NAME}:${BUILD_NUMBER} .'
+                sh 'docker build -t easapi${BRANCH_NAME}:${BUILD_NUMBER} .'
             }
         }
         stage('Test') {

+ 1 - 1
docker-compose.yml

@@ -1,7 +1,7 @@
 version: "3"
 services:
   eas-project-api:
-    image: ${BRANCH_NAME}:${BUILD_NUMBER}
+    image: easapi${BRANCH_NAME}:${BUILD_NUMBER}
     ports:
       - 11004:8080
     networks: