Jenkins Job: Build and Deploy App remotely - ShoppinPal/gcp-scripts GitHub Wiki
Configure a build
Create Jenkins Job
-
Create a new job. The link to get started looks something like:
https://<jenkins-server>/view/All/newJob -
Type:
free style -
Check
This build is parameterizedGive default values for all parameters, otherwise build triggered via git will fail. -
Add
String Parameter -
Name:
VM_EXTERNAL_IP -
Default Value:
<jenkins-server>* ex:jenkins-staging.shoppinpal.com -
Add
File Parameter -
File location:
<File Location>* ex:server/boot/seed.json -
Description:
<description> -
Add
String Parameter -
Name:
IW_STOCK_ORDER_WORKER_NAME -
Default Value:
<default_IW_STOCK_ORDER_WORKER_NAME> -
Add
String Parameter -
Name:
IW_OAUTH_TOKEN -
Default Value:
<default_IW_OAUTH_TOKEN > -
Add
String Parameter -
Name:
IW_URL -
Default Value:
<default_ IW_URL> -
Add
String Parameter -
Name:
VEND_CLIENT_ID -
Default Value:
<default_VEND_CLIENT_ID> -
Add
String Parameter -
Name:
VEND_CLIENT_SECRET -
Default Value:
<default_VEND_CLIENT_SECRET> -
In
Source Code ManagementchooseGit -
Repository URL:
https://github.com/ShoppinPal/warehouse -
Branch:
develop -
Repository Browser select
AUTO -
In
Build TriggerscheckBuild when a change is pushed to GitHub -
In
BuildAdd Build StepExecute Shelland give following commands as build steps
sanity check VM_EXTERNAL_IP by spitting it out in the logs
echo $VM_EXTERNAL_IP
add a configuration file which should never be checked in to source
rather it should be controlled by the build process, like we do here
echo '{ "restApiRoot": "/api", "host": "0.0.0.0", "port": 3000, "aclErrorStatus": 403, "remoting": { "json": { "limit": "50mb" } }, "site": { "baseUrl":"https://'"${VM_EXTERNAL_IP}"'", "proxyUrl": "" }, "logging": { "console": true, "file": false }, "prestashop":{ "apiKey":"" }, "vend":{ "auth_endpoint":"https://secure.vendhq.com/connect", "token_service":".vendhq.com/api/1.0/token", "client_id":"'"${VEND_CLIENT_ID}"'", "client_secret":"'"${VEND_CLIENT_SECRET}"'" }, "ironWorkersUrl":"'"${IW_URL}"'", "ironWorkersOauthToken":"'"${IW_OAUTH_TOKEN}"'", "stockOrderWorker":"'"${IW_STOCK_ORDER_WORKER_NAME}"'" }' > server/config.staging.json
sanity check configuration by spitting it out in the logs
cat server/config.staging.json
install dependencies
npm install npm install grunt-cli npm install bower node_modules/bower/bin/bower install
use the "grunt" tool to perform a build that prepares the bits,
that may be deployed to a "staging" environment
node_modules/grunt-cli/bin/grunt deploy:staging ```
- Add
Post-build ActionsasSend build artifacts over ssh - Select the ssh server where your application should be deployed
- Add Transfer Set
- Provide the following
Exec Commandsand leave rest of the fields empty:
```
cd /apps if [ ! -d /apps/ ]; then mkdir /apps fi if [ ! -d /apps/warehouse ]; then git clone https://github.com/ShoppinPal/warehouse --branch develop fi cd /apps/warehouse git pull
sanity check VM_EXTERNAL_IP on remote server by spitting it out in the logs
echo $VM_EXTERNAL_IP
add a configuration file which should never be checked in to source
rather it should be controlled by the build process, like we do here
echo '{ "restApiRoot": "/api", "host": "0.0.0.0", "port": 3000, "aclErrorStatus": 403, "remoting": { "json": { "limit": "50mb" } }, "site": { "baseUrl":"https://'"${VM_EXTERNAL_IP}"'", "proxyUrl": "" }, "logging": { "console": true, "file": false }, "prestashop":{ "apiKey":"" }, "vend":{ "auth_endpoint":"https://secure.vendhq.com/connect", "token_service":".vendhq.com/api/1.0/token", "client_id":"'"${VEND_CLIENT_ID}"'", "client_secret":"'"${VEND_CLIENT_SECRET}"'" }, "ironWorkersUrl":"'"${IW_URL}"'", "ironWorkersOauthToken":"'"${IW_OAUTH_TOKEN}"'", "stockOrderWorker":"'"${IW_STOCK_ORDER_WORKER_NAME}"'" }' > server/config.staging.json
sanity check configuration by spitting it out in the logs
cat server/config.staging.json
install dependencies
npm install npm install grunt-cli npm install bower node_modules/bower/bin/bower install --allow-root
use the "grunt" tool to perform a build that prepares the bits,
that may be deployed to a "staging" environment
node_modules/grunt-cli/bin/grunt deploy:staging ```
-
Add Transfer Set
-
Select Source files given in
File Parameterand leave rest of fields empty. -
Add Transfer Set
-
Provide the following
Exec Commandsand leave rest of the fields empty:
```
cd /apps/warehouse if forever list | grep '/apps/warehouse/server/server.js' ; then echo 'stopping /apps/warehouse/server/server.js' forever stop /apps/warehouse/server/server.js fi if forever list | grep 'server/server.js' ; then echo 'stopping server/server.js' forever stop server/server.js
fi NODE_ENV=staging DEBUG=shoppinpal:,loopback:boot,boot:create-model-instances,boot:create-role-resolver,common:models:* forever start server/server.js
```
- Save Job