Using Wine With Jenkins - jenkins

I have a local Jenkins server on my Windows laptop. I have created and configured a job that can only run on Windows since it uses VBScript and a Windows BAT file. Is it possible to create a similar job that can runs on a Jenkins server in Linux using the Wine utility? The VbScript file and BAT file are given below.
VbScript File
OPTION EXPLICIT
Dim RootFolder, ExecFolder, Command, FSO, Shell
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Shell = CreateObject("WScript.Shell")
RootFolder = FSO.GetParentFolderName(FSO.GetParentFolderName(Wscript.ScriptFullName))
ExecFolder = FSO.GetParentFolderName(Wscript.ScriptFullName)
On Error Resume Next
'Clean previous log files
Call FSO.DeleteFile(ExecFolder & "\*.txt", True)
Call FSO.DeleteFile(RootFolder & "\Test\*.txt", True)
Call FSO.DeleteFile(ExecFolder & "\*.log", True)
'Execute
Command = Chr(34) & RootFolder & "\SoapUI\bin\testrunner.bat" & Chr(34) & " " & Chr(34) & RootFolder & "\Test\Expando.xml" & Chr(34)
Shell.CurrentDirectory = ExecFolder
Call Shell.Run(Command, 1, True)
'WScript.Sleep(20000)
'Shell.SendKeys("~")
testrunner.bat File
#echo off
set SOAPUI_HOME=%~dp0
if exist "%SOAPUI_HOME%..\jre\bin" goto SET_BUNDLED_JAVA
if exist "%JAVA_HOME%" goto SET_SYSTEM_JAVA
echo JAVA_HOME is not set, unexpected results may occur.
echo Set JAVA_HOME to the directory of your local JDK to avoid this message.
goto SET_SYSTEM_JAVA
:SET_BUNDLED_JAVA
set JAVA=%SOAPUI_HOME%..\jre\bin\java
goto END_SETTING_JAVA
:SET_SYSTEM_JAVA
set JAVA=java
:END_SETTING_JAVA
rem init classpath
set CLASSPATH=%SOAPUI_HOME%soapui-5.2.1.jar;%SOAPUI_HOME%..\lib\*
"%JAVA%" -cp "%CLASSPATH%" com.eviware.soapui.tools.JfxrtLocator > %TEMP%\jfxrtpath
set /P JFXRTPATH= < %TEMP%\jfxrtpath
del %TEMP%\jfxrtpath
set CLASSPATH=%CLASSPATH%;%JFXRTPATH%
rem JVM parameters, modify as appropriate
set JAVA_OPTS=-Xms128m -Xmx1024m -Dsoapui.properties=soapui.properties "-Dsoapui.home=%SOAPUI_HOME%\"
if "%SOAPUI_HOME%\" == "" goto START
set JAVA_OPTS=%JAVA_OPTS% -Dsoapui.ext.libraries="%SOAPUI_HOME%ext"
set JAVA_OPTS=%JAVA_OPTS% -Dsoapui.ext.listeners="%SOAPUI_HOME%listeners"
set JAVA_OPTS=%JAVA_OPTS% -Dsoapui.ext.actions="%SOAPUI_HOME%actions"
:START
rem ********* run soapui testcase runner ***********
"%JAVA%" %JAVA_OPTS% com.eviware.soapui.tools.SoapUITestCaseRunner %*

Related

How to get input from user and use it in CMD using DXL?

Hello I have been trying to get user input and store it in a variable, and then use that variable in a CMD. ALL of this in a DXL script!
Take a glance into the code I have tried this but still not working.
string wheretosave = ""
DB exBox = create "Get Path"
DBE stringInn = field(exBox, "ADD Path where to save:", "", 80)
void doGet(DB exBox) {
wheretosave = get stringInn
print wheretosave "\n"
system("cmd.exe /C cd /d wheretosave & dir & PAUSE")
}
apply(exBox, "Get", doGet)
show exBox
to add "wheretosave" to a string, use
system("cmd.exe /C cd /d " wheretosave " & dir & PAUSE")
But I think the system call does not work. When I start a command line and do a command
cmd.exe /C cd /d d:\temp & dir & PAUSE
then I get the dir of the original directory.
#root: ADDITION: my problem was that I did not have a directory d:\temp on my PC...
But after reading your comment, it seems the point was not understood.
To be more precise:
First: there is no interpolation in DXL. If you want to create a string which contains a) some fixed characters, b) the content of a variable (here: wheretosave) and c) some more fixed characters, you have to use a < space > to concanate the three parts. So, do it like this: string s1 = "fixedtexta" wheretosave "fixedtextb".
Second: If the fixed characters contains a quotation mark then you have to escape it with a backslash. So, this example would become to string s2 = "fixedtexta\"" wheretosave "\"fixedtextb" to get fixedtexta"hello world"fixedtextb if wheretosavecontains hello world
BUT your example is even more difficult.
Third: cmd.exe /C takes only one parameter. So, if you want to do more than one command in the cmd subshell, you have to surround all the commands with enclosing quotation marks cmd.exe /C "cmd 1 & cmd 2 & cmd 3" The way you wrote it would have translated to
create a subshell which does a "cd /d", end the subshell
in the main shell (which is still in the original directory), do a "dir"
in the main shell, do a "pause"
Fourth: In DOS, if you have a quotation mark inside a string, you have to escape it with a second quotation mark.
All in all the command you are looking for is
string wheretosave = "d:\\temp x" // or get stringInn in your example
system("cmd.exe /C \"cd /d \"\"" wheretosave "\"\" & dir & pause\"")
Try providing the full path and apply Mike's correction. Using "C:\Windows" works as expected (for me): the cmd shows the content of my Windows folder on drive C.

Jenkins EnvInject plugin - Environment variable value containing multiple lines

I followed the suggestions from this post on how to use the EnvInject plugin to create and set Jenkins environment variables. I'm using the "Inject environment variables" in post build step and set "Properties File Path"
The windows batch script create a environment variable OPS and writes it to a property file : results.txt which contains multiple lines , like :
OPS= This is line one,
This is two
This is three
Challenge: OPS picks up only the first line from results.txt and skips the rest of the lines.
How do I set OPS have all the lines as its value ?
cd C:\To\Test\Class\Path
java utilities.LogExtractor>ops.txt
#echo off
setlocal EnableDelayedExpansion
set LF=^
rem *** Two empty lines are required for the linefeed
FOR /F "delims=" %%a in (ops.txt) do (
set var=!var!!LF!%%a
)
set var=!var!!LF!
echo OPS=!var! > %JENKINS_HOME%\jobs\%JOB_NAME%\builds\%BUILD_NUMBER%\results.txt
and I set the "Properties File Path" to %JENKINS_HOME%\jobs\%JOB_NAME%\builds\%BUILD_NUMBER%\results.txt
From the source code, I'd say it uses java.util.Properties to load the file, calling the load method. The documentation says you can escape a line break with a backslash, so using
OPS= This is line one,\
This is two\
This is three
should be sufficient. (Be careful, whitespace at the beginning of the line is ommitted.)

checking for existance of ";C:\Python27" before appending ";C:\Python27" to environment variable PATH

I am using following code to append ";C:\Python27" to environment variable PATH..
#echo off
Setx Path "%PATH%;C:\Python27" -M
PAUSE
but if i run this batch file more than once, it is appending ";C:\Python27" many times that should not happen.
SO i have to check for ;C:\Python27 before appending it to PATH variable.
Is there any command for this purpose?
The following Powershell should do it:
$needPython = $env:path | select-string -NotMatch -SimpleMatch "c:\python27"
if ($needPython) {
[Environment]::SetEnvironmentVariable("tstpath", $env:path + ";c:\python27", "User")
}
You can change User to Machine or Process to set a machine or process level environment variable.
You can run this directly from a powershell prompt.
If you're running this from a dos command line use (you need the full path to your script or .\ if it's in the current directory):
powershell "& '.\myscript.ps1'"

I can't send some command line parameters via Autohotkey to VLC

I can't figure out how to get my audio extractor script working via commandline arguments on ahk. I know the command line argument is correct, as I'm able to get it working through a batch file, but I keep getting the error below. I think I'm probably doing something wrong syntactically but I just can't figure out what.
I'd really appreciate any help. Thanks.
Error: the following variable name contains an illegal character"
channels=2,samplerate=44100}:standard{access="file",mux=dummy,dst="%A_LoopField%.mp3"}
Code:
fileselectfile, File_Name, M3
SplitPath, File_Name, name
Loop, parse, name, `n
if a_index = 2
{
msgbox, %A_LoopField%
Run, "C:\Program Files\VideoLAN\VLC\vlc.exe" "-I dummy -v %File_Name% :sout=#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100}:standard{access="file",mux=dummy,dst="%A_LoopField%.mp3"}"
}
Here is the original batch code if you're curious about the audio extraction function I was talking about
#ECHO OFF
REM Loop through files (Recurse subfolders)
REM Syntax
REM FOR /R [[drive:]path] %%parameter IN (set) DO command
REM
REM Key
REM drive:path : The folder tree where the files are located.
REM
REM set : A set of one or more files. Wildcards must be used.
REM If (set) is a period character (.) then FOR will
REM loop through every folder.
REM
REM command : The command(s) to carry out, including any
REM command-line parameters.
REM
REM %%parameter : A replaceable parameter:
REM in a batch file use %%G (on the command line %G)
FOR /R %%G IN (*.mp3) DO (CALL :SUB_VLC "%%G")
FOR /R %%G IN (*.mp3.mp*) DO (CALL :SUB_RENAME "%%G")
GOTO :eof
:SUB_VLC
SET _firstbit=%1
SET _qt="
CALL SET _newnm=%%_firstbit:%_qt%=%%
SET _commanm=%_newnm:,=_COMMA_%
REM echo %_commanm%
ECHO Transcoding %1
REM Here's where the actual transcoding/conversion happens. The next line
REM fires off a command to VLC.exe with the relevant arguments:
CALL "C:\Program Files\VideoLAN\VLC\vlc" -I dummy -v %1 :sout=#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100}:standard{access="file",mux=dummy,dst="%_commanm%.mp3"} vlc://quit
REM Having no SLEEP-esque command, we have to trick DOS/Windows into pausing
REM for a bit between encode ops - To give the host OS a chance to do what it
REM needs to - Via clever use of the PING utility:
REM (Thanks to http://www.computing.net/answers/programming/dos-command-for-wait-5-seconds/11192.html for the tip! :-)
PING -n 1 -w 10000 1.1.1.1 > NUL
GOTO :eof
:SUB_RENAME
SET _origfnm=%1
SET _endbit=%_origfnm:*.mp3=%
CALL SET _newfilenm=%%_origfnm:.mp3%_endbit%=.mp3%%
SET _newfilenm=%_newfilenm:_COMMA_=,%
COPY %1 %_newfilenm%
GOTO :eof
:eof
REM My own little addition to prevent the batch window from "vanishing" without
REM trace at the end of execution, as if a critical error had occurred.
PAUSE
Have you tried without the SplitPath, File_Name, name? I got rid of the error like this, but I don't know if it produces the result you want in the end.
I found the answer. I was making syntatical errors I just didn't have the knowledge to fix myself. The new RUN statement works perfectly.
Here is the newly revised script
fileselectfile, File_Name, M3
SplitPath, File_Name, name, dir, ext, name_no_ext, drive
StringReplace, File_Name, File_Name,`n, \
Loop, parse, name, `n
{if a_index = 2
msgbox, %A_LoopField%
Run % "C:\Program Files\VideoLAN\VLC\vlc.exe -I dummy -v """ File_Name """ :sout=#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100}:standard{access=""file"",mux=dummy,dst=""" A_LoopField ".mp3""} "
}

Executing bat file and returning the prompt

I have a problem with cruisecontrol where an ant scripts executes a bat file that doesn't give me the prompt back. As a result, the project in cruisecontrol keeps on bulding forever until I restart cruisecontrol. How can I resolve this?
It's a startup.bat from wowza (Streaming Server) that I'm executing:
#echo off
call setenv.bat
if not %WMSENVOK% == "true" goto end
set _WINDOWNAME="Wowza Media Server 2"
set _EXESERVER=
if "%1"=="newwindow" (
set _EXESERVER=start %_WINDOWNAME%
shift
)
set CLASSPATH="%WMSAPP_HOME%\bin\wms-bootstrap.jar"
rem cacls jmxremote.password /P username:R
rem cacls jmxremote.access /P username:R
rem NOTE: Here you can configure the JVM's built in JMX interface.
rem See the "Server Management Console and Monitoring" chapter
rem of the "User's Guide" for more information on how to configure the
rem remote JMX interface in the [install-dir]/conf/Server.xml file.
set JMXOPTIONS=-Dcom.sun.management.jmxremote=true
rem set JMXOPTIONS=%JMXOPTIONS%
-Djava.rmi.server.hostname=192.168.1.7
rem set JMXOPTIONS=%JMXOPTIONS%
-Dcom.sun.management.jmxremote.port=1099
rem set JMXOPTIONS=%JMXOPTIONS%
-Dcom.sun.management.jmxremote.authenticate=false
rem set JMXOPTIONS=%JMXOPTIONS%
-Dcom.sun.management.jmxremote.ssl=false
rem set JMXOPTIONS=%JMXOPTIONS%
-Dcom.sun.management.jmxremote.password.file=
"%WMSCONFIG_HOME%/conf/jmxremote.password"
rem set JMXOPTIONS=%JMXOPTIONS% -Dcom.sun.management.jmxremote.access.file=
"%WMSCONFIG_HOME%/conf/jmxremote.access"
rem log interceptor com.wowza.wms.logging.LogNotify
- see Javadocs for ILogNotify
%_EXESERVER% "%_EXECJAVA%" %JAVA_OPTS% %JMXOPTIONS%
-Dcom.wowza.wms.AppHome="%WMSAPP_HOME%"
-Dcom.wowza.wms.ConfigURL="%WMSCONFIG_URL%"
-Dcom.wowza.wms.ConfigHome="%WMSCONFIG_HOME%"
-cp %CLASSPATH% com.wowza.wms.bootstrap.Bootstrap start
:end
From a first look it seems that adding a start command to the line where the server is started might help, i.e.:
start "" %_EXESERVER% "%_EXECJAVA%" %JAVA_OPTS% %JMXOPTIONS%
-Dcom.wowza.wms.AppHome="%WMSAPP_HOME%"
-Dcom.wowza.wms.ConfigURL="%WMSCONFIG_URL%"
-Dcom.wowza.wms.ConfigHome="%WMSCONFIG_HOME%"
-cp %CLASSPATH% com.wowza.wms.bootstrap.Bootstrap start

Resources