Queuing a build using Powershell - powershell

I want to use a powershell script to queue a TFS build( prompting the user to enter the custom build defination) and wait until the build completes and check the status of that build and do a copy if it succeeds or exit if it fails. I would like to thank you in advance for taking time to answer my question

The simplest way is to use tfsbuild.exe command. This tool is located in Drive:\Program Files\Microsoft Visual Studio xx\Common7\IDE. More detail info to use start command: https://msdn.microsoft.com/en-us/library/ms181742(v=vs.100).aspx
You can also use a script using the APIs, How to queue another TFS (2012) Build from a TFS Build AND pass process parameters?
Which things your want to copy? In the build definition, you can specify a drop folder to copy your build outputs in it.

Related

TFS 2015 Build step Nuget Publisher "Ambiguous option 's'"

OK, so we're stuck on on-site TFS2015 at the moment. My Nuget Publisher build step is failing with:
##[error]Ambiguous option 's'. Possible values: Source SymbolSource SymbolApiKey.
It appears inside the build step they have put -s instead of -source, and in later versions they've added more commands starting with s. So what are my options?
Write my own in Powershell (Can do, but TFS Build is very clunky for this)
Find wherever this is defined in TFS (hopefully a template .ps file) and fix it there (Anyone know where this is kept?)
Upgrade to a later version of TFS (a fairly large, but perhaps inevitable undertaking)
Somehow override the -s command another way?
????????
Invoke NuGet.exe however you'd like via the Command Line task
If you did #3 (upgrade TFS), you'd find that the PowerShell build task can run an in-line PowerShell script, making it significantly less clunky.
You may be able to extract and modify the task with the tfx command line utility, but I can almost guarantee this will have nasty ramifications when you do eventually upgrade.
I'm adding my answer for details about step 5 maybe it will help team that are still using TFS 2015.
Nuget Publisher seems to use old version, which means "-s" option will not work.
To bypass this situation you can setup your build as follow:
1- Add Nuget Packager Step and specify the the Package Folder value:
2- Add a new step which would copy your artifacts(Note that contents that should be copied must end with nupkg):
3- And Finaly you can just run a command line that will perform the publish operation. In my case we are pushing the whole repository using init command(PackageRepository is the path to our internal feed that we set in we've set in Variables section):

Build project using devenv.exe in TFS 15RC1 Build Server

I have a trouble with understanding how to use devenv.exe from TFS Build Server.
There is no default step to use devenv, so I tried to use PowerShell sсript to execute devenv.exe with parameters. There are no errors in build process but I see that build result files are not updated.
If I execute the script manually on a agent-machine, the build passes successfully. That is my script:
$process = [System.Diagnostics.Process]::Start( "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe", "/Rebuild ""MyConfig"" ""C:\agent\agent\_work\1\s\MyProject.sln"" /Project ""C:\agent\agent\_work\1\s\MyProject\MyProject.dwproj""")
$process.WaitForExit()
As you see now I do not use variables for source paths, but I will use it if script will work.
I also have to say that I could not find any logs with errors. Maybe I do not know where to find them?
So,
What am I doing wrong in powershell script?
What is the best practice to build project using devenv.exe in TFS Build Server?
PS We are using TFS 15 RC1 (Version 15.103.25603.0).
For now, there is no this build-in feature to support directly using devenv.exe in vNext build task. But seems will coming in the near future:
That is not something we are working on right now, but it is something
that we would take a pull request for.
chrisrpatterson commented on Jan 8
We want an input on the existing Visual Studio Build task that says
use devenv (defaults to false). If true, it takes the variant path
running code similar to above.
bryanmacfarlane commented on Jan 22
Source from GitHUB:
"Visual Studio Build" build step that actually invokes devenv.com instead of msbuild?
visual studio command-line build vnext step (devenv.com)
You can try to use a pull request provide by jmacnett which creating a customize build task.
I found that it doesn't work only when the agent is running as a service. When I started the agent in the interactive mode, my tasks started to work correctly. Why? - I don't know.
$argumentList = ("`"$solnPath`" /$solnCmdSwitch $solnConfigName")
if project then add folowing
$argumentList += (" /project `"$projPath`" /projectconfig $projConfigName")
See the extra back-quotes

Pause TFS build definition via powershell

I would like to create a powershell script that pauses a TFS build definition programmatically. So far, tf.exe doesn't seem to offer any kind of functionality for that. Is there any library or api I can use to achieve this?
There is no easy way known to do that in TFS build. Perhaps stop the build service(the build will hang up ) can be easily executed when the scheduled scripts are running.

Get Build Version in automated build deployment using TFS

I am deploying web application to azure using TFS CI automated build deployment.
In our config maintain build version like 2014.05.19.1 which is $(Date).$(rev) format.
All I want to update config each time build is deployed.For that I am passing value to 'BuildVersion' parameter in template to powershell script which actually performs publishing to azure.
I tried using $(Date:yyyyMMdd)$(Rev:.r) but it is considered string as it is.
I want to get current build version just like IBuildDetail.BuildNumber
within template.
My question is how to get the build version?
If you are using Invoke Process, instead of passing value for BuildVersion parameter you can directly use 'BuildDetail.BuildNumber' in parameters for process like
String.Format("-BuildNumber ""{0}""",BuildDetail.BuildNumber)
This would give the required build number.
If your PowerShell script is being executed from your TFS build, it should have access to the environment variables specific to the TFS context of the build. If that is the case, you actually don't need to pass the $(BuildVersion) parameter to the script, as it already is accessible to the PS script in the $env:TF_BUILD_BUILDNUMBER environment variable. Try testing something like $env:TF_BUILD_BUILDNUMBER | Out-File "D:\Dev\BuildNumber.txt" in your script. You should hopefully see the file containing your build number after running your build.
(I am assuming you are using a relatively new build process template...one that contains the "Post-Build script path" parameter, such as TfvcTemplate.12.xaml)
Hope this is helpful.
I would recommend that you use the right tool for the right job. The build system, is really only for building (compile & test). We have been using it for other things for years coz we did not have another integrated solution. However Microsoft recently bought InRelease and rebranded as Release Management for Visual Studio 2013. I have successfully integrated this with TFS 2012 as well.

Automatization Build Server TFS 2008 (vs 2008)

I use VS 2008, Team Explorer and TFS. I'm looking to automate your builds by executing TFSBuild.exe command.
I follow those steps:
Open TeamExplorer, in VS2008, connected to TFS;
My Team Project has a Build (named MainBuild) in Builds. Then, I do Query New build option.
I fill the properties in window dialog opened:
build Definition: Mainbuild
Build Agent: Machine1BuildAgent
drop folder for this build: \Machine1\Build_drop
priority in queue: Normal
MsBuild command-line arguments:
/p:BuildAll=false /p:RunTest=false /p:SkipClean=true /p:SkipGet=true /p:SkipLabel=true /p:SkipGetChangesetsAndUpdateWorkItems=true
In MDSN I have seen TFSBuild command and this sample:
The following example builds the Nightlies build type which is in the AdventureWorks team project on server01. The resulting build is located on Machine1 in the BuildDrop directory.
TFSBuild start http://server01:8080 AdventureWorks Nightlies /m:Machine1 /d:"C:\BuildDrop"
edit: Now, for my issue, how can I do automation for build MainBuild for set the values for "MsBuild command-line arguments" using TFSBuild.exe command ? I'm looking for a way to automatically have the TFS Build Agent job run nightly with command-line arguments..
I need similar command line like this:
TFSBuild start http://machine01:8080 MyteamProject MainBuild /m:Machine1 /d:"\Machine1\Build_drop" /p:BuildAll=false /p:RunTest=false /p:SkipClean=true /p:SkipGet=true /p:SkipLabel=true /p:SkipGetChangesetsAndUpdateWorkItems=true
I need pass the arguments (MsBuild command-line arguments) to TFSBuild.exe command and automatize the TFS build.
any sample scripting code ?
You can pass MSBuild properties to TFSBuild using the /msBuildArguments switch
TFSBuild start http://machine01:8080 MyteamProject MainBuild /m:Machine1 /d:"\Machine\Build_drop"
/msBuildArguments:"/p:BuildAll=false;/p:RunTest=false;/p:SkipClean=true;
/p:SkipGet=true;/p:SkipLabel=true;/p:SkipGetChangesetsAndUpdateWorkItems=true"
Alternatively, you could also specify these properties in the response file TFSBuild.rsp.
I'm not sure I understand your question clearly, but if you're looking to automate your builds by executing MSBuild from the command-line, you can create a batch file to execute the necessary command using the command-line arguments you want. Then add a scheduled task to 'Scheduled Tasks' in Windows so that this batch file is executed on a regular (e.g. nightly) basis.