{"id":479,"date":"2016-04-16T12:07:44","date_gmt":"2016-04-16T04:07:44","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=479"},"modified":"2018-09-04T23:05:12","modified_gmt":"2018-09-04T15:05:12","slug":"how-i-make-my-jenkins-slave-windows-service-recognize-the-global-modules-installed-by-npm","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/how-i-make-my-jenkins-slave-windows-service-recognize-the-global-modules-installed-by-npm\/","title":{"rendered":"How I make my Jenkins Slave Windows Service recognize the global modules installed by npm"},"content":{"rendered":"<p>I was trying to setup a <a href=\"https:\/\/jenkins.io\/\" title=\"Link to Jenkins home page\" target=\"_blank\">Jenkins<\/a> Slave on a Windows machine which will get <a href=\"http:\/\/angular.github.io\/protractor\" title=\"Protractor home page\" target=\"_blank\">protractor<\/a> to run a series of functional tests that the team had written to test our <a href=\"https:\/\/angularjs.org\/\" title=\"AngularJS homepage\" target=\"_blank\">AngularJS<\/a> application. <\/p>\n<p>Idea was that whenever that there was a code change being committed to the master branch on our <a href=\"https:\/\/github.com\/\" title=\"Link to GitHub home page\" target=\"_blank\">GitHub<\/a> repository, the Jenkins Slave will be called upon to checkout the latest codes and get protractor to run the functional tests base from a <code>configuration.js<\/code> file in the codebase.  <\/p>\n<p>One of the hurdles that I encountered was that my Jenkins Slave Windows Service was not able to recognize the executables from Node.js modules that were installed by npm globally, which in this case was the protractor executable.<\/p>\n<p>This post describes the steps that I took in order to make Jenkins Slave Windows Service recognize the global modules installed by npm.<\/p>\n<h3>\n'protractor' is not recognized as an internal or external command, operable program or batch file.<br \/>\n<\/h3>\n<p>After I had configured and assigned a build job to my Jenkins Slave Windows Service, I got the above message in the console output of my build job. <\/p>\n<p>I encountered this message even though I was able to run protractor through a command prompt instance; <code><a href=\"https:\/\/nodejs.org\/dist\/v4.4.3\/node-v4.4.3-x64.msi\" title=\"Download link for Node.js 4.4.3 on a Windows x64 machine\" target=\"_blank\">Node.js 4.4.3<\/a><\/code> was installed and <code>npm install -g protractor<\/code> was ran through the command prompt.<\/p>\n<p>Why can't my Jenkins recognize protractor as an internal or external command, operable program or batch file?<\/p>\n<h3>Finding out where npm had installed my global modules<\/h3>\n<p>The first diagnostic task that I performed was to check out where my npm program had installed my global Node.js modules.<\/p>\n<p>By typing <code>npm list -g<\/code>, I was able to see the following output:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nC:\\Users\\Administrator\\AppData\\Roaming\\npm\r\n\u2514\u2500\u252c protractor@3.2.2\r\n  \u251c\u2500\u2500 adm-zip@0.4.7\r\n  \u251c\u2500\u252c glob@6.0.4\r\n  \u2502 \u251c\u2500\u252c inflight@1.0.4\r\n  \u2502 \u2502 \u2514\u2500\u2500 wrappy@1.0.1\r\n  \u2502 \u251c\u2500\u2500 inherits@2.0.1\r\n  \u2502 \u251c\u2500\u252c minimatch@3.0.0\r\n  \u2502 \u2502 \u2514\u2500\u252c brace-expansion@1.1.3\r\n  \u2502 \u2502   \u251c\u2500\u2500 balanced-match@0.3.0\r\n  \u2502 \u2502   \u2514\u2500\u2500 concat-map@0.0.1\r\n  \u2502 \u251c\u2500\u252c once@1.3.3\r\n  \u2502 \u2502 \u2514\u2500\u2500 wrappy@1.0.1\r\n  \u2502 \u2514\u2500\u2500 path-is-absolute@1.0.0\r\n  \u251c\u2500\u252c jasmine@2.4.1\r\n  \u2502 \u251c\u2500\u2500 exit@0.1.2\r\n  \u2502 \u251c\u2500\u252c glob@3.2.11\r\n  \u2502 \u2502 \u251c\u2500\u2500 inherits@2.0.1\r\n  \u2502 \u2502 \u2514\u2500\u252c minimatch@0.3.0\r\n  \u2502 \u2502   \u251c\u2500\u2500 lru-cache@2.7.3\r\n  \u2502 \u2502   \u2514\u2500\u2500 sigmund@1.0.1\r\n  \u2502 \u2514\u2500\u2500 jasmine-core@2.4.1\r\n  \u251c\u2500\u2500 jasminewd2@0.0.8\r\n  \u251c\u2500\u252c optimist@0.6.1\r\n  \u2502 \u251c\u2500\u2500 minimist@0.0.10\r\n  \u2502 \u2514\u2500\u2500 wordwrap@0.0.3\r\n  \u251c\u2500\u2500 q@1.4.1\r\n  \u251c\u2500\u252c request@2.67.0\r\n  \u2502 \u251c\u2500\u2500 aws-sign2@0.6.0\r\n  \u2502 \u251c\u2500\u252c bl@1.0.3\r\n  \u2502 \u2502 \u2514\u2500\u252c readable-stream@2.0.6\r\n  \u2502 \u2502   \u251c\u2500\u2500 core-util-is@1.0.2\r\n  \u2502 \u2502   \u251c\u2500\u2500 inherits@2.0.1\r\n  \u2502 \u2502   \u251c\u2500\u2500 isarray@1.0.0\r\n  \u2502 \u2502   \u251c\u2500\u2500 process-nextick-args@1.0.6\r\n  \u2502 \u2502   \u251c\u2500\u2500 string_decoder@0.10.31\r\n  \u2502 \u2502   \u2514\u2500\u2500 util-deprecate@1.0.2\r\n  \u2502 \u251c\u2500\u2500 caseless@0.11.0\r\n  \u2502 \u251c\u2500\u252c combined-stream@1.0.5\r\n  \u2502 \u2502 \u2514\u2500\u2500 delayed-stream@1.0.0\r\n  \u2502 \u251c\u2500\u2500 extend@3.0.0\r\n  \u2502 \u251c\u2500\u2500 forever-agent@0.6.1\r\n  \u2502 \u251c\u2500\u252c form-data@1.0.0-rc4\r\n  \u2502 \u2502 \u2514\u2500\u2500 async@1.5.2\r\n  \u2502 \u251c\u2500\u252c har-validator@2.0.6\r\n  \u2502 \u2502 \u251c\u2500\u252c chalk@1.1.3\r\n  \u2502 \u2502 \u2502 \u251c\u2500\u2500 ansi-styles@2.2.1\r\n  \u2502 \u2502 \u2502 \u251c\u2500\u2500 escape-string-regexp@1.0.5\r\n  \u2502 \u2502 \u2502 \u251c\u2500\u252c has-ansi@2.0.0\r\n  \u2502 \u2502 \u2502 \u2502 \u2514\u2500\u2500 ansi-regex@2.0.0\r\n  \u2502 \u2502 \u2502 \u251c\u2500\u252c strip-ansi@3.0.1\r\n  \u2502 \u2502 \u2502 \u2502 \u2514\u2500\u2500 ansi-regex@2.0.0\r\n  \u2502 \u2502 \u2502 \u2514\u2500\u2500 supports-color@2.0.0\r\n  \u2502 \u2502 \u251c\u2500\u252c commander@2.9.0\r\n  \u2502 \u2502 \u2502 \u2514\u2500\u2500 graceful-readlink@1.0.1\r\n  \u2502 \u2502 \u251c\u2500\u252c is-my-json-valid@2.13.1\r\n  \u2502 \u2502 \u2502 \u251c\u2500\u2500 generate-function@2.0.0\r\n  \u2502 \u2502 \u2502 \u251c\u2500\u252c generate-object-property@1.2.0\r\n  \u2502 \u2502 \u2502 \u2502 \u2514\u2500\u2500 is-property@1.0.2\r\n  \u2502 \u2502 \u2502 \u251c\u2500\u2500 jsonpointer@2.0.0\r\n  \u2502 \u2502 \u2502 \u2514\u2500\u2500 xtend@4.0.1\r\n  \u2502 \u2502 \u2514\u2500\u252c pinkie-promise@2.0.1\r\n  \u2502 \u2502   \u2514\u2500\u2500 pinkie@2.0.4\r\n  \u2502 \u251c\u2500\u252c hawk@3.1.3\r\n  \u2502 \u2502 \u251c\u2500\u2500 boom@2.10.1\r\n  \u2502 \u2502 \u251c\u2500\u2500 cryptiles@2.0.5\r\n  \u2502 \u2502 \u251c\u2500\u2500 hoek@2.16.3\r\n  \u2502 \u2502 \u2514\u2500\u2500 sntp@1.0.9\r\n  \u2502 \u251c\u2500\u252c http-signature@1.1.1\r\n  \u2502 \u2502 \u251c\u2500\u2500 assert-plus@0.2.0\r\n  \u2502 \u2502 \u251c\u2500\u252c jsprim@1.2.2\r\n  \u2502 \u2502 \u2502 \u251c\u2500\u2500 extsprintf@1.0.2\r\n  \u2502 \u2502 \u2502 \u251c\u2500\u2500 json-schema@0.2.2\r\n  \u2502 \u2502 \u2502 \u2514\u2500\u2500 verror@1.3.6\r\n  \u2502 \u2502 \u2514\u2500\u252c sshpk@1.7.4\r\n  \u2502 \u2502   \u251c\u2500\u2500 asn1@0.2.3\r\n  \u2502 \u2502   \u251c\u2500\u252c dashdash@1.13.0\r\n  \u2502 \u2502   \u2502 \u2514\u2500\u2500 assert-plus@1.0.0\r\n  \u2502 \u2502   \u251c\u2500\u2500 ecc-jsbn@0.1.1\r\n  \u2502 \u2502   \u251c\u2500\u2500 jodid25519@1.0.2\r\n  \u2502 \u2502   \u251c\u2500\u2500 jsbn@0.1.0\r\n  \u2502 \u2502   \u2514\u2500\u2500 tweetnacl@0.14.3\r\n  \u2502 \u251c\u2500\u2500 is-typedarray@1.0.0\r\n  \u2502 \u251c\u2500\u2500 isstream@0.1.2\r\n  \u2502 \u251c\u2500\u2500 json-stringify-safe@5.0.1\r\n  \u2502 \u251c\u2500\u252c mime-types@2.1.10\r\n  \u2502 \u2502 \u2514\u2500\u2500 mime-db@1.22.0\r\n  \u2502 \u251c\u2500\u2500 node-uuid@1.4.7\r\n  \u2502 \u251c\u2500\u2500 oauth-sign@0.8.1\r\n  \u2502 \u251c\u2500\u2500 qs@5.2.0\r\n  \u2502 \u251c\u2500\u2500 stringstream@0.0.5\r\n  \u2502 \u251c\u2500\u2500 tough-cookie@2.2.2\r\n  \u2502 \u2514\u2500\u2500 tunnel-agent@0.4.2\r\n  \u251c\u2500\u252c saucelabs@1.0.1\r\n  \u2502 \u2514\u2500\u252c https-proxy-agent@1.0.0\r\n  \u2502   \u251c\u2500\u252c agent-base@2.0.1\r\n  \u2502   \u2502 \u2514\u2500\u2500 semver@5.0.3\r\n  \u2502   \u251c\u2500\u252c debug@2.2.0\r\n  \u2502   \u2502 \u2514\u2500\u2500 ms@0.7.1\r\n  \u2502   \u2514\u2500\u2500 extend@3.0.0\r\n  \u251c\u2500\u252c selenium-webdriver@2.52.0\r\n  \u2502 \u251c\u2500\u2500 adm-zip@0.4.4\r\n  \u2502 \u251c\u2500\u252c rimraf@2.5.2\r\n  \u2502 \u2502 \u2514\u2500\u252c glob@7.0.3\r\n  \u2502 \u2502   \u251c\u2500\u252c inflight@1.0.4\r\n  \u2502 \u2502   \u2502 \u2514\u2500\u2500 wrappy@1.0.1\r\n  \u2502 \u2502   \u251c\u2500\u2500 inherits@2.0.1\r\n  \u2502 \u2502   \u251c\u2500\u252c minimatch@3.0.0\r\n  \u2502 \u2502   \u2502 \u2514\u2500\u252c brace-expansion@1.1.3\r\n  \u2502 \u2502   \u2502   \u251c\u2500\u2500 balanced-match@0.3.0\r\n  \u2502 \u2502   \u2502   \u2514\u2500\u2500 concat-map@0.0.1\r\n  \u2502 \u2502   \u251c\u2500\u252c once@1.3.3\r\n  \u2502 \u2502   \u2502 \u2514\u2500\u2500 wrappy@1.0.1\r\n  \u2502 \u2502   \u2514\u2500\u2500 path-is-absolute@1.0.0\r\n  \u2502 \u251c\u2500\u2500 tmp@0.0.24\r\n  \u2502 \u251c\u2500\u252c ws@1.1.0\r\n  \u2502 \u2502 \u251c\u2500\u2500 options@0.0.6\r\n  \u2502 \u2502 \u2514\u2500\u2500 ultron@1.0.2\r\n  \u2502 \u2514\u2500\u252c xml2js@0.4.4\r\n  \u2502   \u251c\u2500\u2500 sax@0.6.1\r\n  \u2502   \u2514\u2500\u2500 xmlbuilder@8.2.2\r\n  \u2514\u2500\u252c source-map-support@0.4.0\r\n    \u2514\u2500\u252c source-map@0.1.32\r\n      \u2514\u2500\u2500 amdefine@1.0.0\r\n<\/pre>\n<p>From this output, I got to know that my global Node.js modules were installed in the <code>C:\\Users\\Administrator\\AppData\\Roaming\\npm<\/code> directory. And inside that directory, I saw the protractor.cmd file. <\/p>\n<h3>Making Jenkins Slave Windows Service recognize the global modules installed by npm<\/h3>\n<p>After knowing where my global Node.js modules reside in, I went on to check the <code>PATH<\/code> environment variable. I realised that the PATH environment variables in the 'User variables for Administrator' panel is set to the directory where my global Node.js modules reside in, but the PATH environment variables in the 'System Variables' section does not contain that value. <\/p>\n<p>This explains why my Jenkins Slave Windows Service was not able to recognize the protractor executable even though I was able to run protractor via the local Administrator account. <\/p>\n<p>Hence, in order to make my Jenkins Slave Windows Service recognize the the global modules (including my protractor executable)  installed by npm, <strong>I included <code>C:\\Users\\Administrator\\AppData\\Roaming\\npm<\/code> in the Path environment variable in the 'System Variables' section<\/strong>.<\/p>\n<p>With that, I managed to achieve continuous functional testing of my <a href=\"https:\/\/angularjs.org\/\" title=\"Link to AngularJS home page\" target=\"_blank\">AngularJS<\/a> application.<\/p>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-7J\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-7J&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-7J&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F479&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>I was trying to setup a <a href=\"https:\/\/jenkins.io\/\" title=\"Link to Jenkins home page\" target=\"_blank\">Jenkins<\/a> Slave on a Windows machine which will get <a href=\"http:\/\/angular.github.io\/protractor\" title=\"Protractor home page\" target=\"_blank\">protractor<\/a> to run a series of functional tests that the team had written to test our <a href=\"https:\/\/angularjs.org\/\" title=\"AngularJS homepage\" target=\"_blank\">AngularJS<\/a> application. <\/p>\n<p>Idea was that whenever that there was a code change being committed to the master branch on our <a href=\"https:\/\/github.com\/\" title=\"Link to GitHub home page\" target=\"_blank\">GitHub<\/a> repository, the Jenkins Slave will be called upon to checkout the latest codes and get protractor to run the functional tests base from a <code>configuration.js<\/code> file in the codebase.  <\/p>\n<p>One of the hurdles that I encountered was that my Jenkins Slave Windows Service was not able to recognize the executables from Node.js modules that were installed by npm globally, which in this case was the protractor executable.<\/p>\n<p>This post describes the steps that I took in order to make Jenkins Slave Windows Service recognize the global modules installed by npm.<\/p>\n","protected":false},"author":1,"featured_media":1249,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[4],"tags":[246,245,244,248,247,195],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Jenkins-Logo.gif","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-7J","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/479"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=479"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/479\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1249"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}