Sfoglia il codice sorgente

Added Jenkins file for CI

xiaoct 7 anni fa
parent
commit
3522dcba3e
3 ha cambiato i file con 59 aggiunte e 0 eliminazioni
  1. 23 0
      Jenkins/Jenkinsfile
  2. 29 0
      Jenkins/scripts/deliver.sh
  3. 7 0
      Jenkins/scripts/kill.sh

+ 23 - 0
Jenkins/Jenkinsfile

@@ -0,0 +1,23 @@
+pipeline {
+    agent {
+        docker {
+            image 'node'
+            args '-p 80:80'
+        }
+    }
+    stages {
+        stage('Build'){
+            steps {
+                sh 'npm install'
+            }
+        }
+        stage('Deliver'){
+            steps {
+                sh './jenkins/scripts/deliver.sh'
+                input message: 'Finished using the web site? (Click "Proceed" to continue)'
+                sh './jenkins/scripts/kill.sh'
+            }
+        }
+            
+    }
+}

+ 29 - 0
Jenkins/scripts/deliver.sh

@@ -0,0 +1,29 @@
+#!/usr/bin/env sh
+
+echo 'The following "npm" command builds your Node.js/React application for'
+echo 'production in the local "build" directory (i.e. within the'
+echo '"/var/jenkins_home/workspace/simple-node-js-react-app" directory),'
+echo 'correctly bundles React in production mode and optimizes the build for'
+echo 'the best performance.'
+set -x
+npm run build
+set +x
+
+echo 'The following "npm" command runs your Node.js/React application in'
+echo 'development mode and makes the application available for web browsing.'
+echo 'The "npm start" command has a trailing ampersand so that the command runs'
+echo 'as a background process (i.e. asynchronously). Otherwise, this command'
+echo 'can pause running builds of CI/CD applications indefinitely. "npm start"'
+echo 'is followed by another command that retrieves the process ID (PID) value'
+echo 'of the previously run process (i.e. "npm start") and writes this value to'
+echo 'the file ".pidfile".'
+set -x
+npm start &
+sleep 1
+echo $! > .pidfile
+set +x
+
+echo 'Now...'
+echo 'Visit http://localhost:80 to see your Node.js/React application in action.'
+echo '(This is why you specified the "args ''-p 3000:3000''" parameter when you'
+echo 'created your initial Pipeline as a Jenkinsfile.)'

+ 7 - 0
Jenkins/scripts/kill.sh

@@ -0,0 +1,7 @@
+#!/usr/bin/env sh
+
+echo 'The following command terminates the "npm start" process using its PID'
+echo '(written to ".pidfile"), all of which were conducted when "deliver.sh"'
+echo 'was executed.'
+set -x
+kill $(cat .pidfile)