fauzanooor 3 anni fa
parent
commit
4397aa4038
2 ha cambiato i file con 61 aggiunte e 24 eliminazioni
  1. 30 24
      Jenkinsfile
  2. 31 0
      Jenkinsfile-bak

+ 30 - 24
Jenkinsfile

@@ -1,31 +1,37 @@
-node {
-  try {
-    stage('Checkout') {
-      checkout scm
-    }
-    stage('Initialize'){
-      def dockerHome = tool 'myDocker'
-      env.PATH = "${dockerHome}/bin:${env.PATH}"
+pipeline {
+  environment {
+    registry = "10.2.200.235:50006"
+    registryCredential = 'localregistry'
+    dockerImage = ''
+  }
+  agent any
+  tools {nodejs "node" }
+  stages {
+    stage('Cloning Git') {
+      steps {
+        git 'http://10.2.200.235:50002/appsptb/ptb-next'
+      }
     }
-    stage('Environment') {
-      sh 'git --version'
-      echo "Branch: master"
-      sh 'docker -v'
-      sh 'printenv'
+    stage('Building image') {
+      steps{
+        script {
+          dockerImage = docker.build registry + ":$BUILD_NUMBER"
+        }
+      }
     }
-    stage('Build Docker test'){
-     sh 'docker build -t ptb-fe -f Dockerfile .'
+    stage('Deploy Image') {
+      steps{
+         script {
+            docker.withRegistry( '', registryCredential ) {
+            dockerImage.push()
+          }
+        }
+      }
     }
-    stage('Deploy'){
-      if(env.BRANCH_NAME == 'master'){
-        sh 'docker build -t ptb-fe .'
-        sh 'docker tag ptb-fe localhost:50006/ptb-fe'
-        sh 'docker push localhost:50006/ptb-fe'
-        sh 'docker rmi -f ptb-fe localhost:50006/ptb-fe'
+    stage('Remove Unused docker image') {
+      steps{
+        sh "docker rmi $registry:$BUILD_NUMBER"
       }
     }
   }
-  catch (err) {
-    throw err
-  }
 }

+ 31 - 0
Jenkinsfile-bak

@@ -0,0 +1,31 @@
+node {
+  try {
+    stage('Checkout') {
+      checkout scm
+    }
+    stage('Initialize'){
+      def dockerHome = tool 'myDocker'
+      env.PATH = "${dockerHome}/bin:${env.PATH}"
+    }
+    stage('Environment') {
+      sh 'git --version'
+      echo "Branch: master"
+      sh 'docker -v'
+      sh 'printenv'
+    }
+    stage('Build Docker test'){
+     sh 'docker build -t ptb-fe -f Dockerfile .'
+    }
+    stage('Deploy'){
+      if(env.BRANCH_NAME == 'master'){
+        sh 'docker build -t ptb-fe .'
+        sh 'docker tag ptb-fe localhost:50006/ptb-fe'
+        sh 'docker push localhost:50006/ptb-fe'
+        sh 'docker rmi -f ptb-fe localhost:50006/ptb-fe'
+      }
+    }
+  }
+  catch (err) {
+    throw err
+  }
+}