I have a batchfile ( see code below ).
Because the tf command must be executed in the Visual Studio command prompt.
I call the visual studio command.
But then the batch file stops executing.
Somebody have an idea?
REM #echo off
REM ... Change the path below. This is the path where the code will be downloaded!
REM Z:
REM cd Backup_TFS_Preview
call %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86
REM ... Navigate to folder
Z:
cd Backup_TFS_Preview
REM ... Makes folder with date today
mkdir %Date:~-10,2%-%Date:~-7,2%-%Date:~-4,4%
REM ... Navigate to folder
cd %Date:~-10,2%-%Date:~-7,2%-%Date:~-4,4%
REM ... Add workspace for the folder with date of today
tf workspace /new %Date:~-10,2%-%Date:~-7,2%-%Date:~-4,4% /noprompt
REM ... Get all items from TFS
tf get /recursive /all /noprompt
REM ... Navigate to folder
cd ..
REM ... Zip the folder
C:\TFS_Backup_Scripts\7z.exe a %Date:~-10,2%-%Date:~-7,2%-%Date:~-4,4%.zip %Date:~-10,2%-%Date:~-7,2%-%Date:~-4,4%\
REM ... Remove folder
rmdir %Date:~-10,2%-%Date:~-7,2%-%Date:~-4,4%\ /s /q
REM ... Delete workspace
tf workspace /delete %Date:~-10,2%-%Date:~-7,2%-%Date:~-4,4% /noprompt
REM ... Navigate to folder
cd ..
cd ..
REM ... Delete zip files that are older then 10 days
forfiles -p "Z:\Backup_TFS_Preview" -s -m *.* -d -10 -c "cmd /c del /q #path"
%comspec% /k runs another command prompt, and then keeps cmd.exe around. Until that cmd.exe returns, your batch file won't continue.
Even if you replace /k with /c (which doesn't keep cmd.exe around), it won't work, because the environment variables from the new command prompt aren't preserved in this one.
You simply need:
call %VS100COMNTOOLS%\vsvars32.bat
Or
call %VS100COMNTOOLS%\..\..\VC\vcvarsall.bat x86
what happens when you execute the call from a cmd prompt?
also note the exit code (0 or 1) for vcvars32.bat (which is called by vcvarsall.bat) so run: Echo %errorlevel%
after you run vcvarsall.bat. if it is zero the command completed successfully.
and you might try and remove the dbl "" like this:
call %comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
that could break the cmd statement up into bad pararameters due to the spaces not being escaped
maybe test for the %errorlevel% right after the call line
last resort, change the /k to /c in the call statement.
post results
I solved it in another way. I used the full path of the tf.exe. And it works in the command prompt.
The call answer doens't worked for me.
Related
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
I m trying to build a project from codewarrior IDE command line. It works fine when i run it manually on the windows slave as:
CmdIDE.exe C:\Jenkins\build\workspace\project_name\xxxxxxxx.mcp /b /c /q
But when i try to run the build from Jenkins nothing happens and it keeps on running. I tried to do this from a batch script using psexec but still no response. Please help if anyone has done this from jenkins.
C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.3\bin>CmdIDE.exe 'C:\project_name\xxxxxxxx.mcp' /b /c /q
Freescale CodeWarrior IDE. Hit /? for help ERROR: Process Aborted. (Code 9)
C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.3\bin>exit 9 Build step 'Execute Windows batch command' marked build as failure
Thanks in advance
i am trying to execute devenv.exe through windows batch command plugin in Jenkins
but it keeps on executing and fails to launch the application.
Console Output :
**In progressConsole Output
Started by user anonymous
Building on master in workspace C:\Program Files (x86)\Jenkins\jobs\TEMP\workspace
[workspace] $ cmd /c call C:\Windows\TEMP\hudson3900292017086958332.bat
C:\Program Files (x86)\Jenkins\jobs\TEMP\workspace>set DEVPATH=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
C:\Program Files (x86)\Jenkins\jobs\TEMP\workspace>set PATH=D:\app\nazopay\product\11.2.0\dbhome_1\bin;D:\app\nazopay\product\11.2.0\client_1;C:\Program Files (x86)\Integrity\IntegrityClient10\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\cde\tools;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.6.0_23\bin\;C:\Program Files (x86)\Google\Chrome\Application;C:\MingW;C:\PROGRA~2\INTEGR~1\Toolkit\mksnt;%JAVA_HOME%;,;C:\Program Files\Java\jdk1.6.0_23;,;C:\Program Files\Java\jdk1.6.0_23\bin;%CLASS_PATH%;,;C:\Program Files\Java\jdk1.6.0_23\lib;,;C:\Program Files\Java\jdk1.6.0_23\lib;;C:\Program Files (x86)\M**icrosoft Visual Studio 10.0\Common7\IDE
C:\Program Files (x86)\Jenkins\jobs\TEMP\workspace>devenv.exe
You must execute devenv.com.
The devenv.exe always attempts to open GUI, even when commands are given, and it can't. The devenv.com has output directed to standard output and works fine from Jenkins.
You also must pass arguments.
Without arguments both devenv.com and devenv.exe just start the IDE GUI, which is not what you want. The correct command-line is
devenv.com projectname.sln /Build Release /Project projectname
First is path to the solution you want to build. Then the /Build flag is followed by configuration. If you have multiple platforms, you have to pass configuration and platform combination, e.g. Release|Win32. The /Project flag names project to build (including all dependencies). If omitted, it builds all projects selected for build in given configuration.
Why don't you use msbuild?
This would be a good starting point for your windows build script:
call "%VS100COMNTOOLS%\vsvars32.bat"
msbuild projectname.sln /target:Rebuild /l:FileLogger,Microsoft.Build.Engine;logfile=msbuild.log || goto error
goto end
:error
#echo ERROR: Build failed
exit/b 1
:end
exit/b 0
This way you can also capture the output log that you can parse with one of the jenkins plugins.
Ofcourse, adjust the VS100COMNTOOLS to your version of MSVS
Following is the bat script code block on which i am working on:
ECHO off
IF NOT EXIST "%ANT_HOME%" (
SET ANT_HOME=%~dp0%build\apache-ant-1.8.2
SET ANT_BIN=%~dp0%build\apache-ant-1.8.2\bin
SET PATH | FIND "%ANT_HOME%;%ANT_BIN%"
)
cd "build\Run"
ant -q
cd ../..
echo "Program Terminated!"
exit
Now, my build.xml file is inside this build\Run folder so that i am first navigating to build/Run before running ant -q command (NOTE: I don't want to change this method of navigating).
The moment ant -q command is executed following things happen:
Set the environment variables as the condition.
Change directory to build\Run.
As my build.xml is inside the Run directory the ant -q command run correctly.
Ant executed correctly and not ant script terminates.
Now my current path will be build\Run ! correct <= Here i don't want this after ant is terminated, instead i want to come out from build\Run that's why i used cd../..
But the problem is I am not able to execute the commands after ant -q. This happens be the program control goes from BATCH => ANT.
Is there any way to execute my command after ant command from bat script itself ?
You may find that the ant being run is a batch file itself, in which case it simply chains to it (no return).
You should try this instead:
call ant -q
Calling a batch file (as opposed to chaining) will correctly return to the point after which you called it.
I'm trying to add the following folder tree to TFS:
C:\TFS\folder1
C:\TFS\folder1\folder2
C:\TFS\folder1\folder2\folder3
C:\TFS\folder1\folder2\folder3\test.txt
In the above example the folder "C:\TFS" is a mapped TFS working folder. I issue the following commands from the console:
cd C:\TFS
tf add folder1 /recursive
After this command has finished my repository contains the following tree (as pending changes):
$/folder1
$/folder1/folder2
As you can see "folder3" and the text file "test.txt" below are completely missing! Why?
Update: I've submitted this as a bug to Microsoft:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=423279
from microsoft the basic command goes as follows:
tf add itemspec [/lock:(none|checkin|checkout)] [/type:filetype]
[/noprompt] [/recursive] [/login:username,[password]]
I typed in the following command and it worked fine:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\tf.exe" add itemspec /r "where to add to"
you run the command from the folder you want to copy files and in the command under "where to add to" you type the destination
worked for me.
c:\Temp>md Test\1\2\3\4\5
c:\Temp>dir test /s/b
c:\Temp\test\1
c:\Temp\test\1\2
c:\Temp\test\1\2\3
c:\Temp\test\1\2\3\4
c:\Temp\test\1\2\3\4\5
c:\Temp>cd test
c:\Temp\Test>tf add 1 /recursive
1
1:
2
1\2:
3
1\2\3:
4
1\2\3\4:
5
c:\Temp\Test>
In Tfs
Same if I do it from Test or above Test directory