Jenkins fails "shell exec" task for paths with quotes - jenkins

I have windows based Jenkins host and local folder like this:
"c:\Archive\JenkinsBuilds"
When I'm using shell exec to copy build to that folder (all the content of Release folder) I'm getting an error. The issue is because Jenkins adds single quotes automatically and shell exec expectes double quotes only:
I defined env variables:
FINAL_PACKAGE = My-Project\bin\Release
BUILDS_DEST = c:\Archive\JenkinsBuilds\My-Project\$BUILD_NUMBER
and shell exec:
xcopy /i /f /v $FINAL_PACKAGE $BUILDS_DEST
And during execution I see in logs:
xcopy /i /f /v 'My-Project\bin\Release' 'c:\Archive\JenkinsBuilds\My-Project\17'
How to force Jenkins to use double quotes.
If I specify them manually Jenkins adds single quotes in any case what generates the same error:
"Invalid number of parameters"

Thanks to #Cole9350 for advise.
On windows it is better to use windows batch command
And variables usage will be different:
xcopy /i /f /v "%FINAL_PACKAGE%" "%BUILDS_DEST%"

Related

How to build a Delphi project in TeamCity

I am trying to build a delphi project in TeamCity, but I can't get it to work.
I'm using MSBuild to build the project and also have added BDS parameter to the build but I keep getting the error: MSB4040 There is no target in the project.
There are several things you need to be aware of. Firstly, the various environment variables and paths that Delphi requires need to be setup. Much of this is accomplished by the rsvars.bat batch file, but you can set up your own. Secondly, your EnvOptions.proj file needs to be set correctly to match the environment on your build machine. This file resides in %APPDATA%\Embarcadero\xx,x\ where xx.x is your Delphi version.
The following commented CMD file is one that I use to build Delphi XE7 applications in a TFS environment and should work with TeamCity and other build tools :-
#echo off
:::
::: Example for Build Delphi Project with MSBuild
:::
echo.
echo using MSBuild from VStudio 2013
echo.
SET MSBUILD_EXE=C:\Program Files (x86)\MSBuild\12.0\bin\MSBuild.exe
echo.
echo A copy of a Delphi installation from a developers machine is ok. MSBuild calls dcc32/dcc64, not the IDE.
echo The build targets are included in "$(DelphiInstallDir)\bin\CodeGear.Delphi.Targets".
echo DefaultTarget is "Make"
echo.
echo.
echo Set Delphi XE7 Vars
echo.
SET BDS=C:\DelphiXE7
SET BDSBIN=%BDS%\bin
SET BDSLIB=%BDS%\lib
SET BDSTMP=%BDS%\Temp
echo.
echo On a local Delphi developer machine the actual used Delphi settings are located here:
echo "%APPDATA%\Embarcadero\BDS\15.0\EnvOptions.proj"
echo.
echo The directories and files included in "EnvOptions.proj" must exist on the build machine!!!
echo.
echo Copy the (maybe modified) Delphi settings on your build machine to %APPDATA%\Embarcadero\BDS\15.0
echo.
MKDIR "%APPDATA%\Embarcadero\BDS\15.0"
COPY /Y /B /V "%BDSTMP%\EnvOptions.proj" "%APPDATA%\Embarcadero\BDS\15.0\EnvOptions.proj"
echo.
echo Set the Delphi Project Vars
echo.
SET PROJECT_SRC=C:\MyProjectSource
SET PLATFORM=Win32
SET CONFIG=Debug
echo.
echo Build Delphi Project with MSBuild
echo.
echo + /p = Parameters for the Delphi Project Build
echo.
echo + /t = Targets to be executed, e.g. Clean and Build
echo.
"%MSBUILD_EXE%" "%PROJECT_SRC%\myProject\myProject1.dproj" /p:Config=%CONFIG%;Platform=%PLATFORM% /t:Clean;Build
IF NOT ERRORLEVEL 0 GOTO ERROR
GOTO END
:ERROR
echo.
echo There were errors!
echo.
pause
EXIT
:END
pause
You could correct setup teamcity to build using MSBuild using the follow steps:
First you should define the parameter on teamcity that declares the enviroment variables that is seted by rsvars.bat, to do that in your Project access the Parameters and create a new configuration, select the type enviroment variable, set the same names and values from the rsvars.bat file aka: BDS, BDSCOMMONDIR, et all.
After that in you msbuild step edit the target option to "build".
You can see that this information is documented here http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Building_a_Project_Using_an_MSBuild_Command
Here you can see my params configuration
And here is the MSBuild Project configuration

Jenkins: Escaping % in parameterized jobs

I'm trying to run this command from shell as a build step on a Windows machine:
for /R . %f in (*.bin) do copy "%f" "..\Release\"
After struggling for a while figuring out why it doesn't work, I noticed this is a parameterized build and that parameters are of the form %var%. I assume is trying to replace % with an empty value since there's nothing defined. It is translated to on the first loop:
for /R . f" "..\Release\Newer\"
I guess I could define a parameter like %f% = %f and it might do the trick, but seems unnecessary.
First, I assume you are using Windows environment (you should really specify), and as such it is not a "shell" build step, but "Execute Windows Batch Command" build step (if it's not, you need to use "Execute Windows Batch Command" build step)
Next, it's a peculiarity of Windows Batch, that when you run it from command line, you can use a single % in the FOR statement, however when you run it from a batch file (and the batch build step is a temporary batch file), you need to use %%. Note, this only applies to the FOR statement as it uses a special syntax for the variables.
So change your line to:
for /R . %%f in (*.bin) do copy "%%f" "..\Release\"

Jenkins Mstest plugin strips out the double quotes in the command line while trying to run multiple test categories

Trying to get multiple test categories run via Jenkins mstest plugin command line gives a error
Command line Auguments :/testsettings:Test\Tests\Local.testsettings /category:"!FAIL&!LIVE"
gives
Console output :cmd.exe /C "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe" /resultsfile:Test\Tests\TestResults\Endpoints\Tests.trx /testsettings:Test\Tests\Local.testsettings /category:!FAIL&!LIVE /testcontainer:Test\Tests\Tests\bin\Endpoints\Tests.dll && exit %%ERRORLEVEL%%
Error:'!LIVE' is not recognized as an internal or external command,
Manual run via cmd : "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe" /resultsfile:Test\Tests\TestResults\Endpoints\Tests.trx /testsettings:Test\Tests\Local.testsettings /category:!FAIL&!LIVE /testcontainer:Test\Tests\Tests\bin\Endpoints\Tests.dll
This works when run via cmd but not with jenkins plugin
How do I get jenkins plugin not to strip out the quotes ? Or is there any other way.
I think it's a bug related with https://issues.jenkins-ci.org/browse/JENKINS-13412

Parameterized build Jenkins

I have configured a job in Jenkins and checked "This build is parameterized" option. The parameter name I have given is "My_Param". The Jenkins is installed in the server machine. So I access the Jenkins dashboard through http://<servername>:8080/ In the Build part, I have to call a script by opening cygwin. So I write
#!C:\cygwin\bin\bash --login -i
./build/myscript.sh -full
After the build is completed, I want to move the files to another new directory prefix with Output, This directory name is the parameter I intend to pass. so I write
mkdir /cygdrive/c/users/admin/Ouput$My_Param
I run the build and pass param as first
But, the directory is created as Output in the server machine and not as Outputfirst
Since you noted you use cygwin, I understand the server is on windows.
Try parameter windows style environment variable: %My_Param% or linux: ${My_Param}
I hope this helps.

Trying to run one command in "Execute Shell" and a python script in Jenkins (formerly hudson) under "build"

These run on the command line in linux (ubuntu) but when trying to run them via hudson, only the first one (first one) shows up in the console Output
From comment:
nosetests -s --with-coverage --cover-package prus find . -name "*test.py"
pylint --rcfile scripts/pylintrc -f parseable prus > pylint.txt echo "pylint complete"
sloccount --wide --details prus > sloccount.sc
It looks like your piping the output from 2 into pylint.txt, and 3 is being piped into sloccount.sc. You need to pipe to both stdout and to the file in order to get your files populates, as well as have the output go to Hudson. Take a look at tee.exe, it will do that for you.

Resources