Skip to content

Jenkins Job: Build and Deploy App locally

Faisal Ali Rabbani edited this page May 16, 2015 · 9 revisions

Configure a build

Create Jenkins Job

  1. Create a new job. The link to get started looks something like: https://<jenkins-server>/view/All/newJob
  2. Type: free style
  3. Check This build is parameterized
  4. Add String Parameter
  5. Name: VM_EXTERNAL_IP
  6. Default Value: <jenkins-server> * ex: jenkins-staging.shoppinpal.com
  7. Add File Parameter
  8. Add File Parameter
  9. File location: <File Location> * ex: server/boot/seed.json
  10. Description: <description>
  11. In Source Code Management choose Git
  12. Repository URL: https://github.com/ShoppinPal/warehouse
  13. Branch: develop
  14. Repository Browser select AUTO
  15. In Build Triggers check Build when a change is pushed to GitHub
  16. In Build Add Build Step Execute Shell and give following commands as build steps
  17. @faisalrabbani - TODO: Is there a way to save the super long echo string as an environment variable and then spit it out like so: echo -e $STAGING_CONFIG in the build?
  18. @faisalrabbani - TODO: Is there some way to setup variable in Jenkins so that only the admin you created them can see the values but other jenkins users can still use them in their builds?
  19. @faisalrabbani - TODO: Please parameterize the following: IW_STOCK_ORDER_WORKER_NAME, IW_OAUTH_TOKEN, IW_URL, VEND_CLIENT_ID, VEND_CLIENT_SECRET, VM_EXTERNAL_PORT and update the echo blah blah string to make use of those variables ... both here in the docs and in the actual jenkins build
```

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}"':3000", "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":"", "client_secret":"" }, "ironWorkersUrl":"https://worker-aws-us-east-1.iron.io:443/2/projects//tasks/webhook", "ironWorkersOauthToken":"", "stockOrderWorker":"" }' > 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 ```

  1. Add Post-build Actions as Send build artifacts over ssh

  2. Select the ssh server where your application should be deployed

  3. Provide the following Exec Commands and leave rest of the fields empty:

rm -r /apps/warehouse cp -r /var/lib/jenkins/workspace/warehouse /apps cp server/boot/seed.json /apps/warehouse/server/boot/ 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 ```

  1. Save Job

Clone this wiki locally