How do I get a grunt task working with a Cloudbees Jenkins build

社会主义新天地 提交于 2019-12-04 23:47:01

问题


I'm trying to get a Jenkins build up and running on Cloudbees. I've successfully gotten NodeJs installed and my source pulled from my BitBucket repository. I am trying to run my grunt task to minify and concatenate my JS and CSS files before deploying. However, I am not able to run the grunt program, even though it is successfully installed. Below is my build script:

curl -s -o use-node https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/node/use-node
NODE_VERSION=0.8.0 \
 source ./use-node
npm install
npm install grunt
grunt

I've tried installing grunt with and without the -g option without success. Here is the console output for the grunt portion of my build:

+ npm install grunt
...
npm http GET https://registry.npmjs.org/grunt
npm http 200 https://registry.npmjs.org/grunt
...
grunt@0.4.0 node_modules/grunt
├── dateformat@1.0.2-1.2.3
├── colors@0.6.0-1
├── hooker@0.2.3
├── eventemitter2@0.4.11
├── which@1.0.5
├── iconv-lite@0.2.7
├── coffee-script@1.3.3
├── lodash@0.9.2
├── nopt@1.0.10 (abbrev@1.0.4)
├── rimraf@2.0.3 (graceful-fs@1.1.14)
├── minimatch@0.2.11 (sigmund@1.0.0, lru-cache@2.2.2)
├── glob@3.1.21 (graceful-fs@1.2.0, inherits@1.0.0)
├── findup-sync@0.1.2 (lodash@1.0.1)
└── js-yaml@1.0.3 (argparse@0.1.12)
+ grunt
/tmp/hudson3382014549646667419.sh: line 8: grunt: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

Any ideas on how to get this working? Is this even possible in Cloudbees?


回答1:


Grunt is now broken up, annoyingly, into a separate cli module. Also, annoyingly, that cli module does not include grunt itself.

To make this work:

curl -s -o use-node https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/node/use-node
NODE_VERSION=0.8.0 \
 source ./use-node
npm install
npm install grunt
npm install grunt-cli
export PATH=$PATH:node_modules/grunt-cli/bin/
grunt

If the folk making this change how it works to be sensible, then it may change in future.

Docs here: http://gruntjs.com/getting-started




回答2:


you can setup everything from a jenkins job, no ssh/command line required:

Install Jenkins Plugins

  • Git Plugin - for git
  • Git Client Plugin - for git
  • Git Parameter Plugin - for git tags
  • GitHub API Plugin - for github
  • NodeJS Plugin - integration for common javascript tools NodeJS & npm

Git / Ant / Maven / NodeJS Installations

  • Goto SERVER/jenkins/configure
Git
  • Git -> Git installations -> Add Git -> JGit
  • Git plugin -> Global Config user.name Value = "Anthony Mckale", Global Config user.email Value = "anthony.mckale@bskyb.com"
NodeJS
  • NodeJS- > NodeJS installations -> Add NodeJS -> Name = "NodeJS 0.11.10", tick "Install automatically", select "Install from nodejs.org", add "grunt-cli" to globally installed packages

TADA

and hopefully git/nodejs and grunt will be available to you

see the plugin wiki for more details how to add the grunt/node tasks to the jenkins job -> https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin

it's really easy :)

no ssh loggin required just jenkins admin rights



来源:https://stackoverflow.com/questions/15318841/how-do-i-get-a-grunt-task-working-with-a-cloudbees-jenkins-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!