Collabnet post-commit hook fails to execute Perl script - windows

I'm trying to set up the Slack Subversion integration. I use Collabnet Edge under Windows. The Slack site suggests a Perl script (Here) to call. I've installed Dwimperl, and written a batch file to run the script, passing the parameters to the perl script. This all works correctly if I call it manually from the commandline, however when it's called by Subversion something clearly goes amiss as I don't see anything in my Slack channels.
The batch file has one line:
C:\Dwimperl\perl\bin\perl.exe C:\csvn\data\repositories\repo\hooks\slacknotify.pl %1 %2
I've verified that the hook is being called after a commit by echoing %1 and %2 to a file, and that behaves as I expect.
My guess is that Subversion calls the batch file without some environment vars set, or something along those lines, but I'm completely unfamiliar with Perl and I don't know which. I'm calling the perl executable by absolute path, so even if %PATH% is blank I think it should work.
A related question is: how do I go about debugging issues like this? The Collabnet log files have nothing in them than I can see

In this case it was simply the PATH variable that needed setting. Specifically
SET PATH=C:\Dwimperl\perl\bin;C:\Dwimperl\perl\site\bin;C:\Dwimperl\c\bin
at the start of the batch file has solved the problem.

Related

Windows command prompt custom commands

I am looking for a way to customise some of the Windows command prompt (cmd.exe) commands. I would like the new command to be called instead of the one defined by Windows to do almost the same thing except some minor customisations. An example could be with the pushd command print a message saying which directory is changing to. This could be useful, for example, to have the output a .bat script parsed by another tool.
As an example, pushd.bat would look like:
#echo off
pushd %1
echo Entering directory `%cd%'
...but where should I put this so that it gets called instead of the internal command pushd?
You should not customize internal commands because some of these commands go all the way back to DOS and have hidden bugs and features that some tools might rely on and it is unlikely that you will implement them correctly.
You can add custom aliases with doskey. These are better than batch files. They allow you to add certain mini scripts that help you in your daily command line usage. These can actually override the names of internal commands.
doskey pushd=echo Entering $*^&pushd $*
pushd c:\Windows
You can add your doskey commands to HKCU\Software\Microsoft\Command Processor\AutoRun in the registry but you really need to be careful if you use it to change existing commands. I recommend that you invent new names for your commands.

Shell Script to Batch file for Jenkins

I am trying to create a Jenkins build on a windows box, and am running into a situation where I am completely unsure of what to do.
I have the following shell script which I need to convert to a windows batch script for when the build runs. I have I believe gotten the set correct for the variables, just not sure what to do with the rest of it:
#set POWERUSER=DTCURTISS
#set POWERPASS=password
set POWERUSER=auto
set POWERPASS=password
set TAG=$BUILD_NUMBER
set PATH=.env/bin:$PATH
set SAUCEUSER=DarthOpto
set ACCESSKEY=accesskey
set IGNOREPAGEHEADERLOCATION=True
set MAINMENUCLICKTILES=False
set LOGDIR=logs
source ../.env/bin/activate
cd trunk/automation/selenium/src
#pip install -r pip-requires.txt
rm -rf logs
nosetests --nocapture --with-xunitmp -a valallmod --processes=$THREADS --process- timeout=5000
You are not going to get far if you don't know batch-file. Besides, simply "translating" bash to batch is not going to magically make it work on Windows.
Variables are referenced as %VARNAME%, not $VARNAME. Fix that first.
Windows uses \ as path separator, not /. Change all your paths to use \
When you want to append to PATH variable in Windows, you've got to make sure you don't destroy the existing PATH. You do this through set PATH=%PATH%;C:\whatever\yourpath\
Something similar to source would be batch's call followed by another batch file name. However you can't just pass it ../.env/bin/activate as that is not a batch file. You would need to convert that file to batch as well. And don't forget to convert the path separator to \. This is also where my second point comes into play. The file you pasted is rather simple. I've got no idea what's inside that other file or whether it can be "translated".
The # is not a valid comment in batch, you need to use REM or better yet ::
rm and it's flags is not a Windows command. An equivalent would be rmdir /s /q
Finally, nosetests is neither bash nor batch. It's an external program. You've got to make sure it is available in Windows. As a pre-emptive step before your next question, read this: 'nosetests' not recognized on Windows after being installed and added to PATH

svn post-commit hook on windows server

i'm trying to set up a svn post-commit hook on a windows server, so that every time a commit is made, it is connected to an issue of an existing project on my bug tracking website.
since there is no pre made post-commit hook for windows (or at least i haven't find one that would fit my needs), i tried to write the batch file for myself.
SET REPOS=%1
SET REV=%2
SET SVNLOOK="C:\Program Files (x86)\VisualSVN Server\bin\svnlook.exe"
SET PROJECT=3
%SVNLOOK% log -r %REV% "%REPOS%" > COMMIT_MSG
SET /p COMMIT_MSG= < COMMIT_MSG
echo %COMMIT_MSG%
C:\curl\bin\curl "http://www.mybugtrackingsite.de/vcs_integration/report/%PROJECT%/?passkey=KEY" --data-urlencode "msg=%COMMIT_MSG%"
when i'm setting REPOS and REV by myself and run the script from the command line it works, but when i make a commit it doesn't work and my COMMIT_MSG only contains "echo is on" instead of the actual message.
i've read, that the svn repository executes hook programs with an empty environment, means that no environment variables are set at all and that could be why my script runs fine by hand and not when run by svn.
but what variables do i have to set and how? my paths are already absolute, so that shouldn't be the problem. i'm not a windows guy and am not really into batch - so any help or ideas how i get this thing to work would be appreciated!
When you redirect the commit message to the file you use a relative path 'COMMIT_MESSAGE'.
%SVNLOOK% log -r %REV% "%REPOS%" > COMMIT_MSG
The working directory which is used by the svn hook may not be the same as yours and the svn process has not the rights to write at this location. You may use an absolute path.
You can also try to redirect STDERR to see if you get an error from svnlook.
Also delete the file at the beginning of the hook script to ensure that you don't use a file from a previous run.
Your are setting both REPOS and REV to %1. One of them should be %2
You should also place #ECHO OFF at the top of the file to avoid unnecessary output on screen

Windows, ClearCase, and Ant: how to handle directory slashes?

I have a Windows batch script that I use to build a module and the script in turn uses the ClearCase clearmake command to drive the actual compilations, directory creations and file manipulations, i.e. process the Makefile content. The batch script works flawlessly when invoked using a DOS window or from a "cmd /c ..." command line invocation. And it has been that way for some number of years.
I recently decided to move the script to Ant. The first step, out of simplicity, was to simply invoke the script unchanged using an Exec task (using cmd /c). Almost immediately, Ant fails while creating a directory. The error message reports something like:
mkdir: Cannot create the directory C:\\fred\\harry\\joe
I was able to verify that, using the DOS command prompt, the mkdir C:\\fred\\harry\\joe command works fine, so, as near as I can tell so far, Ant generating double backslash path separators combined with something inherent to clearmake and/or something in the Makefile is causing the failure.
The response I'm looking for is something along the lines: "Yes, clearmake is definitely the culprit because..." or "If you twiddle this thing or that thing in Ant, only a single backslash will be generated...". Should there be no simple and quick explanation, I will drill into the problem to determine what exactly is causing the failure.
Thanks,
I have seen similar error with:
dynamic views (more sensible to ownership than a snapshot view on C:\, which is your case)
resource handle conflict (the script tries to update a resource already taken by another process, which shouldn't be the case here with your script, since it was working outside of Ant Exec task)
error message (like you create a directory which already exists: the error get ignored in a classic script, while it could interrupt the ant task.
While the last cause is a good candidate, try first to simplify your script (leave only the mkdir for instance) in order to check that this line is indeed the issue (nd not "this line in conjunction with others actions taking place just before")

CMD: Bat to Exe Converter - Temp directory problem

i am using 'Bat to Exe Converter' to convert my batch files to exe format.
Now, i am running into some problems.
Whenever i convert something, and i set 'Working Directory' to 'Current Directory', and i start my exe in echo on mode, this is what i end up with to check if there is a specific file in the directory of my exe:
the actual command: if not exist "%~dp0\file.txt" goto :nofile
output: if not exist "C:\Users\MyUser\AppData\Local\Temp\4CBC\\file.txt" goto :nofile
Can anyone help me with this? I don't want it in the temp directory, i want it to be in the directory of my exe.
Thanks.
Without having Bat to Exe changed by the author, I think you have two options:
Remove the need for accessing %~dp0
Perhaps you can merge file.txt with the include option of Bat to Exe into the EXE file. If so, "file.txt" will automatically be unpacked in the current directory when running your compiled exe, and you can it access by %CD%\file.txt.
Get %~dp0 from outside and pass it to the exe as a command line parameter.
This can be done by a simple starter bat file that resides in the same directory as your compiled main batch file. This script schould contain the line
YourCompiled.Exe %~dp0% %%*
Your compiled exe then gets its directory from %1. So you cannot pack everything into one exe, but the main portion of it, perhaps that is sufficient for you.
Well, apparently your batch to exe converter simply packs the batch file and extracts it to a temporary directory prior to execution. Very simplistic, hard to get wrong (compared to actually understand the batch file) but it introduces errors such as the one you're describing.
Your best bet is probably to use another batch to exe converter; some of them are actually a little more sophisticated.
Generally, this is not a good idea. firstly, its prone to errors and instability of the converter on different cmd features. secondly, a determined hacker can still decode what you are doing with the batch. My suggestion, if you are so afraid of people looking into your batch,
1) let only the people who are authorized to use your batch to use it
2) give them the correct permissions.
OR, don't use batch at all
1) create a central interface such as a web interface, where all tasks to be done goes through that interface, like using an ATM machine where only buttons are allowed and all the available user options can be done by pushing buttons...etc..
2) authenticate your users through a central authentication system, eg Active Directory, or LDAP or a database.
This is an 2.5 yr old subject but there is an answer to this so I'm posting for anyone else that happens to find this in a search.
B2EC written by Fatih Kodak, has an option to "Submit current directory".
When this is used, you can reference %1 in your batch file to get the path of the EXE that was executed (instead of the path of the extracted BAT that is really being run).
Hovering over that option in the UI shows "Submit the current working directory as the last parameter". The "last parameter" in my use has always been %1 but you can test your code to be sure.
The latest version, 2.1.4 at time of writing, of Bat to Exe by Fatih Kodak creates an Environmental Variable at runtime that can be substituted in place of %~dp0 to reference the Exe's path. Therefore, you can simply replace %-dp0 with %b2eprogrampathname% in the original batch file.
You can use external folders with f2ko's batch to exe converter. Having
a separate folder for subroutines can neaten up a project folder.
To call mysubroutine that is located in mysubroutinesfolder\mysubroutine,
...
pushd mysubroutinesfolder
call mysubroutine
popd
...
The call can be made a one liner:
call xqt mysubroutine
where xqt.cmd is a program that does the call for you:
pushd mysubroutinesfolder
call %*
popd
exit /b
(the %* means "all of the arguments").
In this way your batch programs run as batch, and UNMODIFIED they will
compile with the bat to exe converter, creating a completely folder independent executable. Select "temporary directory",
and include all of the subroutines/executables in your mysubroutines folder
by "selecting them all" with your cursor as usual, then hit "copy".
Be sure to include the xqt.cmd program too; place it "outside" of your mysubroutines folder. Make sure that is is accessible by your main program. Remember to select x64 if you
are runnning on a x64 machine, or the executable will not find SYSTEM32
files. You can find f2k0's batch to exe converter at:
http://www.f2ko.de/programs.php?pid=b2e
Try this development environment for batch scripts, Batch Compiler . It has everything you need to develop a batch program.And compile into stable stand alone executable (Exe).
Friendly user interface.
Debugger, Check your code for syntax errors.
Powerful, versatile compiler.
Allows mouse input in batch files.
Use Windows Common Dialog Boxes.(BrowseFiles,BrowseFolders)
Draw graphics in batch files.
Reverse engineering proof encryption of source code.
Include Company name, Copyright info and Version info.
Make invisible(silent) executables.
Executables with administrator privileges.
Run & debug your script while editing.
Embed resources with executable.(music,images,files)
Advance Commands (BrowseFiles,LaunchSilent,MouseCMD)
Stand-alone executables.No dependencies needed.
Executables are woking on almost all windows operating systems.(98 to 10)
Quick download : http://bc.gotek.info/files/BatchCompiler159.zip
Cheers!
%cd% will give you the current directory:
if not exist "%CD%\file.txt" goto :nofile
Use %CD% instead of %~dp0.
EDIT:
B2EC is not a real converter. Creation location of equipped .cmd file was chosen to be %TEMP% and this is a good choice. Application just lacks 3rd option for working directory of the script - .exe file directory. I advise you to mail the author about adding this one.
Different paths for .exe and created .cmd lead to information loss, i.e. we are unable to know .exe directory and current directory at the same time without providing additional information to the script (e.g. using environment variable or passing it as first/last argument to the script). This script would need to handle it and we would end writing cmd scripts tailored for this converter, which is bad.
%~dp0 - script directory (%TEMP%/.../) - practically useless
%cd% - working directory (as set up in the converter) - currently there are only 2 options: current directory (working directory of .exe) and temporary directory (actually equal to %~dp0, but without trailing backslash)
I think it can be solved by patching cmd.exe instance in memory to change the script path, but that's B2EC developer's duty.
Side note: Normal executable files can be easily executed with specified 0th argument by providing appriopriate lpApplicationName and lpCommandLine to CreateProcess function. Command files are executed via cmd.exe, so 0th argument cannot be set this way.

Resources