From 5b445a09f5eab6ad159d0fcc49737fcaf2909eeb Mon Sep 17 00:00:00 2001 From: cloudyan <1395093509@qq.com> Date: Sun, 8 Nov 2020 09:15:35 +0800 Subject: [PATCH 1/2] feat: test jenkins --- Jenkinsfile | 30 ++++++++++++++++++++++++++++++ scripts/deliver.sh | 28 ++++++++++++++++++++++++++++ scripts/kill.sh | 7 +++++++ scripts/test.sh | 20 ++++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 Jenkinsfile create mode 100644 scripts/deliver.sh create mode 100644 scripts/kill.sh create mode 100644 scripts/test.sh diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000..cf6ea71f5a --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,30 @@ +pipeline { + agent { + docker { + image 'node:6-alpine' + args '-p 3000:3000' + } + } + environment { + CI = 'true' + } + stages { + stage('Build') { + steps { + sh 'npm install' + } + } + stage('Test') { + steps { + sh './jenkins/scripts/test.sh' + } + } + stage('Deliver') { + steps { + sh './jenkins/scripts/deliver.sh' + input message: 'Finished using the web site? (Click "Proceed" to continue)' + sh './jenkins/scripts/kill.sh' + } + } + } +} diff --git a/scripts/deliver.sh b/scripts/deliver.sh new file mode 100644 index 0000000000..8d3a7af6b9 --- /dev/null +++ b/scripts/deliver.sh @@ -0,0 +1,28 @@ +#!/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 appropriate' +echo 'subdirectory of "/var/jenkins_home/workspace/"), correctly bundles React' +echo 'in production mode and optimizes the build for 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:3000 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.)' diff --git a/scripts/kill.sh b/scripts/kill.sh new file mode 100644 index 0000000000..94ae46bf00 --- /dev/null +++ b/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) diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100644 index 0000000000..360d00b94e --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +echo 'The following "npm" command (if executed) installs the "cross-env"' +echo 'dependency into the local "node_modules" directory, which will ultimately' +echo 'be stored in the Jenkins home directory. As described in' +echo 'https://docs.npmjs.com/cli/install,%20the"--save-dev" flag causes the' +echo '"cross-env" dependency to be installed as "devDependencies". For the' +echo 'purposes of this tutorial, this flag is not important. However, when' +echo 'installing this dependency, it would typically be done so using this' +echo 'flag. For a comprehensive explanation about "devDependencies", see' +echo 'https://stackoverflow.com/questions/18875674/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies.' +set -x +# npm install --save-dev cross-env +set +x + +echo 'The following "npm" command tests that your simple Node.js/React' +echo 'application renders satisfactorily. This command actually invokes the test' +echo 'runner Jest (https://facebook.github.io/jest/).' +set -x +npm test From a4bfc627b9f30ebaf394e61bf9e1ae89ab522c5e Mon Sep 17 00:00:00 2001 From: cloudyan <1395093509@qq.com> Date: Tue, 10 Nov 2020 11:20:05 +0800 Subject: [PATCH 2/2] feat: update registry --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 53720bdbbb..c81153db36 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,10 @@ "react-scripts": "1.0.14" }, "scripts": { + "preinstall": "npm config set registry https://registry.npm.taobao.org", "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" } -} \ No newline at end of file +}