I have a teamcity build running grunt as a command line task.
When I execute grunt default the output (in the Teamcity logs) does not contain the relevant error output from grunt. It do however return the appropriate non-zero exit code, which cause the teamcity build to fail correctly. I do not get the grunt error log though.
This page: https://www.npmjs.org/package/grunt-teamcity describes the following workaround for the issue that I'm facing:
Teamcity on windows does not flush the stdout stream before exiting
the grunt node process. There has been some work around this in both
nodejs and grunt, but it is by no means resolved. If you see missing
output in your Teamcity build log then try running the grunt task
using the TC command line runner by redirecting output to a file, e.g:
grunt default --no-color > grunt.tmp & type grunt.tmp & del grunt.tmp
Seems that by redirecting to a file the output is synchronous, whereas
with pipe (or TC plugin execute method) the output is async and not
captured before the node process exits.
So it basically suggest that you run grunt like this: grunt default --no-color > grunt.tmp & type grunt.tmp & del grunt.tmp. The problem with this approach however is that is always return 0 (zero) as the exit code, which mean that my Teamcity build does not properly fail.
I imagine this can be fixed with some creative batch scripting, but I'm not sure how to approach this.
#echo off
:: prepare environment
setlocal enableextensions
set "tempFile=%temp%\%~nx0.%random%.grunt.tmp"
:: run grunt
call grunt default --no-color > "%tempFile%"
:: Keep the grunt exit code
set "exitCode=%ERRORLEVEL%"
:: Print the grunt output
type "%tempFile%"
:: cleanup and exit with adecuated value
del /q "%tempFile%" >nul 2>nul
endlocal & exit /b %exitCode%
call grunt default --no-color > temp.txt
type temp.txt
Related
I'm trying to run a script on startup on my Raspberry Pi, I need to ultimatly run npm run start after everything has loaded in order to launch my Electron app. If I run this command in the terminal it works just fine, but for hours I've been trying to use a crontab, the RC Local and various other things.
My script doesn't run. I can verify that my rc local file is indeed running and my sh file is running, but Electron is never launched, what am I doing wrong?
I've got a command to execute a script that runs in rc.local which is:
sh '/home/pi/Desktop/cockpit-tv-monitor/start.sh'
The contents of start.sh is:
#!/bin/sh
# start-jammer.sh
# navigate to the home directory, then to this directory, then execute python script, then back home
cd /
cd home/pi/Desktop/cockpit-tv-monitor
echo "about to run npm run start" > /tmp/rc_test.txt
npm run start
I am getting the echo, but npm run start seems to never launch my electron app, and this command is essentially an alias which runs electron .
UPDATE 05/05 # 09:58
I've outputted the contents of npm run start to a simple text file using:
npm run start >> /tmp/start-output.txt > 2>&1
The error I'm getting is:
> cockpit-tv-monitor#1.0.0 start
> electron .
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Failed to get 'appData' path
at App.c._setDefaultAppPaths (electron/js2c/browser_init.js:5:1300)
at Object.<anonymous> (electron/js2c/browser_init.js:197:2129)
at Object../lib/browser/init.ts (electron/js2c/browser_init.js:197:3540)
at __webpack_require__ (electron/js2c/browser_init.js:1:128)
at electron/js2c/browser_init.js:1:1200
at electron/js2c/browser_init.js:1:1267
at NativeModule.compileForInternalLoader (internal/bootstrap/loaders.js:283:7)
at NativeModule.compileForPublicLoader (internal/bootstrap/loaders.js:225:10)
at loadNativeModule (internal/modules/cjs/helpers.js:35:9)
at Module._load (internal/modules/cjs/loader.js:747:15)
/home/pi/Desktop/cockpit-tv-monitor/node_modules/electron/dist/electron exited with signal SIGSEGV
This is even after adding a delay before running npm run start of 30s, still get the error.
did you try running it from
/home/pi/.xinitrc
just create that file, and insert
cd /home/pi/Desktop/cockpit-tv-monitor && npm run start &
reboot and hope the best.
The error seems to be Failed to get 'appData' path, which is probably an OS related thing.
appData is where Electron saves its cookies and other electron runtime related items. This might mean that your OS doesn't have the proper directory that electron can save to.
For linux (e.g. Raspberry Pi), it looks for two things either and environment variable called $XDG_CONFIG_HOME or something with this file ~/.config.
You can output the value of either by
echo $XDG_CONFIG_HOME
or
cat ~/.config
to see if a paths exist.
If neither work you can update your npm start script and pass an environment variable on start like XDG_CONFIG_HOME="~/usr/electron/myapp" && electron . that adds the environment variable before boot with a directory.
I've got a Jenkins job set up to run a node.js server in the background, perform some tests on it (through a batch script, using Nightwatch), and then kill off the node server using the TaskKill batch command. Here's the command line script I have for the build:
START /B node ../app.js
runtests.bat
taskkill /F /IM node.exe
The build runs and passes, but it never seems to kill node. At the end of the console output I get:
Process leaked file descriptors. See https://jenkins.io/redirect/troubleshooting/process-leaked-file-descriptors for more information
And I can see the node.exe process still running in my Task Manager.
If I run the same commands in my own command prompt it works fine, and kills node. It's just that Jenkins doesn't seem to execute that last command at all.
Any ideas? Am I maybe taking the wrong approach altogether?
Well I managed to get it working by installing the Hudson Post Build Task plugin, and just killing node in a post-build command. Still not sure why it wasn't working before though.
When I press Ctrl+C in PowerShell, I receive:
Terminate batch job (Y/N)?
Similar to https://superuser.com/questions/35698/how-to-supress-terminate-batch-job-y-n-confirmation, except for Windows PowerShell.
Does PowerShell provide any more control over batch jobs than what CMD does?
The behavior is neither caused by PowerShell nor can PowerShell change it (as evidenced by the PowerShell source-code repo not containing the prompt message).
The behavior is built into cmd.exe - Powershell, in this case, is calling a .cmd file (batch file), which is interpreted by cmd.exe.
If you explicitly control the invocation of the target executable, you can fix this by moving to Powershell - note this has its own considerations, see below.
If you do not explicitly control the invocation of the target executable, you're out of luck (unless you're willing to install third-party cmd.exe replacements) and must press Ctrl+C twice in order to terminate execution.
A[n ill-advised] workaround is to modify the cmd.exe binary - see article with instructions on how to patch the cmd.exe executable in order to suppress the prompt. Additionally, you can post a feature request on GitHub to request that this behavior be fixed at the source, though that is unlikely to happen for reasons of backward compatbility.
To demonstrate the behavior:
The examples assume that Node.js is installed and that node.exe is therefore in your PATH:
First, invoke node.exe directly, with a tight loop that requires you to press Ctrl+C to terminate the process.
PS> node -e "while (true);"
As you'll see, pressing Ctrl+C instantly terminates the process - no confirmation prompt.
Now, let's create a sample batch file that invokes the same command and invoke that batch file:
PS> "#echo off`nnode -e `"while (true);`"" | Set-Content test.cmd
PS> ./test.cmd
As you'll see, pressing Ctrl+C now presents the undesired Terminate batch job (Y/N)? prompt. (You'd get the same behavior if you ran the batch file from cmd.exe.)
To demonstrate that gulp is a cmd file:
You say you're running your command via gulp's CLI.
On Windows, the entry point for the gulp CLI is gulp.cmd [see update in the bottom section] - i.e., a batch file. That is how it works in general for npm-package "binaries" (executables) implemented as either JS files or shell scripts.
That gulp invokes gulp.cmd can be verified as follows:
# Execute from a project folder that has `gulp` installed as a dependency.
# If `gulp` is installed *globally*
# Note: CLI `npx` requires npm version 5.2.0+
PS C:\some\NodeJs\project> npx where gulp
You'll see something like:
C:\some\NodeJs\project\node_modules\.bin\gulp
C:\some\NodeJs\project\node_modules\.bin\gulp.cmd
Note that where.exe also lists the extension-less Unix-shell script, ...\gulp; however, from cmd.exe / Powershell such a shell script isn't directly executable, and it is ...\gulp.cmd - the batch file - that is executed.
(If in doubt, place a command such as #set /p dummy="Press a key" at the start of the gulp.cmd file, and you'll see that this command executes when you invoke gulp without the .cmd extension.
Also note that there is no gulp.exe.)
More generally, on Windows, a project's node_modules\.bin subfolder contains pairs of CLI entry points for the CLIs that come with packages that the project depends on locally:
node_modules\.bin\<some-cli> is the Unix shell script (whose executing interpreter is controlled via its shebang line).
node_modules\.bin\<some-cli>.cmd is the helper batch file for Windows.
Updates and future considerations:
In the context of npm modules, the problem would go away if a PowerShell script (*.ps1) were used as the helper script on Windows. There are tickets for npm, yarn and similar software to do this. There are also some drawbacks:
*.ps1 files aren't directly executable from outside of PowerShell, notably from cmd.exe and File Explorer (and changing that is nontrivial).
PowerShell still hasn't fully replaced cmd.exe as the default shell, as of Windows 10 (and won't anytime soon, if ever).
When called from PowerShell, a *.ps1 file would be found and run in-process, so a possible solution is for the npm project to also provide *.ps1 helper scripts, which would take precedence over *.cmd files of the same name.
Update:
Recent versions of npm (verified in 6.14.10) indeed DO install such *.ps1 files.
Alternative package manager yarn, since v2 does not seem to use batch files anymore at all, so the original problem is bypassed there; (v1, by contrast, still uses batch files (only); upgrading from v1 must be done on a per-project basis see the migration instructions).
As the other answer notes, the correct fix is to replace cmd scripts with ps1 versions.
However another workaround for users of the Hyper shell is 'Hyper yes', a plugin that automatically hits y for you when the prompt comes up.
best way to avoid it is to not start it, in my case, is not to type npm run devStart but instead type nodemon ./server.js localhost 3000
here's how it looks like
#echo off
start /w "" "C:\myfile.bat" 2>nul|findstr /i "termin"
if errorlevel 1 goto bypass
:bypass
echo hello by stexup YouTube channel!
timeout /t 5 >nul
I have set up a basic guard file to watch for css and js in my .net project.
If i do this in the CMD to the project and type "guard" it works great.
How would I get this to be a external command in visual studio? I would need a .bat or .exe to run in the $(project) and pass the guard argument.
What am I missing
I'm not a Windows guy, but you probably want to start Guard in the background with a command like: START /B CMD /C CALL "foo.bat"
You probably also want to set the starting directory to where the Gemfile is, and run bundle exec guard as the command.
Does anyone know how you would run the following command within TeamCity? (the command is normally ran in a Node.js command window)..."Karma start karma.conf.js". I have successfully installed Nodejs on the TeamCity server. I have then successfully installed Karma on the same server (using npm install -g karma).
In TeamCity, my build step has "Runner type = Command Line", and the Custom Script is set to "FULLPATHOFKARMAEXE\karma.cmd start FULLPATHOFKARMACONFIGFILE/kara.conf.js"
When i run TeamCity, it comes back with the error "node is not recognized as an internal or external command"
Anyone know the step-by step process of running Karma within TeamCity?
In your case, the Karma installation seems to be OK, but your TeamCity agent process is unable to resolve the path to Node.exe (it's installation folder is missing from the %PATH% variable).
First verify the NodeJS installation by opening a Commandline window on the agent machine, type node and press enter:
c:> node
>
If the result in your Command window is a >-prompt, you might solve your problems by restarting the build agent.
If the result in your Command window is some error message saying "node is not recognized as an internal or external command", you need to add the NodeJS installation folder to the %PATH% variable, and restart the build agent.
You can, of course, just change the %PATH% for your build agent service by running a initialization script included in the NodeJS installtion folder in your build step. Depending on where your NodeJS installastion is, your custom script might look like this:
"C:\Program Files (x86)\nodejs\nodevars.bat"
"FULLPATHOFKARMAEXE\karma.cmd start FULLPATHOFKARMACONFIGFILE/kara.conf.js"