gulp command not recognized in Jenkins - node.js

I've installed gulp and it works well in my cmd. So when I'm trying the gulp commands they work well. So I'm going to this path in my cmd:
C:\Program Files (x86)\Jenkins\workspace\project1
And I can run gulp (its a github project on my Jenkins).
But when I'm working on my project1 in Jenkins itself (localhost), the gulp commands aren't recognized. Jenkins doesn't know gulp.
How do I have to integrate gulp in Jenkins? So my Jenkins will know its commands. I read something about node.js and its pluging.
I also read something about a frontend-maven-plugin/
but it isn't clear at all.

You need to add the gulp path for Jenkins so it knows where the command resides.
Manage Jenkins-->Configure System-->Global Properties:

If you have gulp defined as your project's dependency then you can also use it directly:
node_modules\.bin\gulp mytask

Related

Pre-build event grunt on build server, not finding grunt

I have been using CoffeeScript files within a project and have installed grunt into the project to compile them.
I am using Grunt Launcher to compile the files manually, but I wanted to be able to do so automatically when the project is built. To this end I put the following in the pre-build event command line under the project properties:
CD $(ProjectDir)
grunt build
This seems to work locally, but when I commit to the build server it comes back with this error:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1063,5): error MSB3073: grunt build" exited with code 9009
My research suggest that this is essentially a file not found; I presume for grunt. Some posts (here and here) suggest that added the full path is the answer, but what is the full path for grunt? Is it something like:
"path-to-project\node_modules\grunt\lib\grunt.js"
Grunt is installed both locally in the project and globally on my PC. I'm using Visual Studio 2012.
Is there anyway to get the build server to run grunt?
Thank you in advanced for any help.
Thank you to anyone who had a look at this question.
After a bit of experimenting I found putting this into the pre-build event command line works:
CD $(ProjectDir)
cmd.exe grunt build

Set up an xcode bot to build and deploy a nodejs express server

I am attempting to set up a xcode project and bot that will build a nodejs application on commit from a github repository and restart the server after the build completes. The bot is currently picking up on the repository changes but fails to build correctly.
I am using a xcode external build tool project that uses /bin/bash as the tool path and the working directory is set to the local repository path.
The bot's after integration script is something like,
npm install --production
npm run build
npm run server:restart
I am getting errors like [npm|node] is not recognized.
Just looking for some clarity to what I might be missing or what could be going wrong.
Add this to the beginning of your script and review the output:
which node
set | grep PATH
This will happen if node is not in your path, which may happen because build scripts have a pretty basic environment - they're not running as a normal user. You may need to add it to your PATH at the start of your build script.

Is it possible to run an script when installing a cordova plugin?

I know when I install a cordova plugin the native files are copied into the platform folder and will be compiled when I build that platform. But is it possible to execute an script to for example download additional binary files, or build custom frameworks?
What I am looking for is a way to specify in plugin.xml to execute a particular shell script or install an npm module when the plugin is first installed into a Cordova project. Is this possible?
That is not possible using the 'cordova plugin add' command (not what they were designed to do) but definitely possible if you use task manager tools like Grunt to automate your process.
You can combine tasks to run in order, such as running your own shell scripts before/after you make a call to install plugins.
Check out npm grunt for more info.
Yes, you can
check this:
https://cordova.apache.org/docs/en/latest/guide/appdev/hooks/index.html
You only have to make a folder, called "after_plugin_add", inside the hooks folder of the project, and add there your script.

Automating coffeescript compilation with Jenkins

I've set up a jenkins CI server on a windows box for one of my projects. There is a portion of it written in Coffeescript. Previously this part wasn't looped into the build process. Now It needs to be.
I haven't seen any coffeescript plugins for jenkins, or much from google on the topic of building coffeescript in jenkins.
I am looking for the simplest way to set up a jenkins build to include a coffee compilation step. Preferably through plugins on jenkins rather then manually installing programs on the box.
Currently the coffeescript is compiled via commands like so
coffee --lint --watch --output "C:\repositories\martha\trunk\bb\app\bin\js/" --compile "C:/repositories/martha/trunk/bb/app/src/"
in the Node.js command prompt on developing boxes
I've also noticed that Jenkins has a node.js plugin where you are capable of running scripts in a build step. I don't believe I can use the commands npm install -g coffee-script or coffee --compile through node.js scripts rather then the command line. Though I hope I am wrong.
Currently the best option I see is to install node.js on the box, use npm to install coffee script, and then run batch scripts as a build step. Though I am willing to pursue this, I would like less manual installation on the box, to ease the use of coffee-script in more projects.
Is this my best option?
Worth saying though I use node.js to compile coffee-script, node.js itself, and its capabilities, are very new to me.
One possible solution is to run the compiler with the script provided in extras/coffee-script.js. You have to use JDK 7 or the latest Rhino (JDK 6 will not work). Here is a link to a simple CoffeeScript compiler in Java
i would recommend
a) installing nodejs plugin + grunt on jenkins -> Jenkins integration with Grunt
b) voting up the excellent instructions :)
c) then using grunt to compile the coffee script, this also means you can easily locally compile coffee script too!!
grunt instructions -> http://gruntjs.com/
grunt coffee script instructions -> https://github.com/gruntjs/grunt-contrib-coffee
basically you need a Gruntfile.js a bit like this
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg : grunt.file.readJSON('package.json'),
coffee: {
compile: {
files: {
'path/to/result.js': 'path/to/source.coffee', // 1:1 compile
'path/to/another.js': ['path/to/sources/*.coffee', 'path/to/more/*.coffee'] // compile and concat into single file
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.registerTask('default', ['grunt-contrib-coffee']);
};
then for the jenkins shell task you just need this, to run grunt and hence coffee script
npm update
grunt

How do I run grunt from a different folder than my root project

Is there a way to tell grunt which grunt.js file to use?
I have an f:\a\b\tools folder that contains grunt.cmd, node.exe,...,
my actual web app with GruntFile.js and all the local node_modules is in f:\a\c\my_app
Running grunt from a\c\my_app works fine but trying to run grunt from some other folder say a does not seem to work. I am new to grunt and may be I am missing something obvious.
f:\a>grunt --config c\GruntFile.js
grunt-cli: The grunt command line interface. (v0.1.6)
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or grunt hasn't been installed locally to your project. For more information about installing and configuring grunt, please see the Getting Started guide:
http://gruntjs.com/getting-started
You can set two parameters --base and --gruntfile
From grunt --help:
--base Specify an alternate base path. By default, all file paths are relative to the Gruntfile. (grunt.file.setBase) *
--gruntfile Specify an alternate Gruntfile. By default, grunt looks in the current or parent directories for the nearest Gruntfile.js or Gruntfile.coffee file.
So, you can execute:
grunt --base c\my_app --gruntfile c\my_app\GruntFile.js mytask
Since grunt 1.3 you can omit --gruntfile.
So, instead of
grunt --base c\my_app --gruntfile c\my_app\GruntFile.js mytask
you can just
grunt --base c\my_app mytask (and --base can be replaced with -b)
I'll advise you to run it from your app directory because the modules are installed into nodes_modules, etc.
you must move to your app directory and run grunt:
cd f:
cd a\c\my_app
grunt {yourTasks}

Resources