consider the following in my powershell step:
-source "c:\builds\$(Build.BuildNumber).zip"
result is "c:\builds\20171005.1.zip"
If I try and set the following in the configuration tab of my release variables of release like this
Name=MyBuildNumber Value=$(Build.BuildNumber)
If I change my poweshell to look like this
-source "c:\builds\$(MyBuildNumber).zip"
result is "c:\builds\$(Build.BuildNumber).zip"
What am I a doing wrong here? I have tried a few different flavours of stored variables all with the same effect. Could really use some advice.
---------AS PER ANDY-MSFT----
I can confirm I am using Version 14.102.25423.0. I installed the variable extension pack.. no difference. The logs show the literal output. I am pretty sure I am using the exact same setup you are. Please check the screenshot of my definition variable and powershell syntax.
What's the exact version of TFS 2015 and the anent version do you use?
I tested on TFS 2015 Update4 (Version 14.114.26403.0, Agent.Version:1.95.4), everything works as expected.
So, please check What version of Team Foundation Server do you have, if you are using earlier version, you can try to upgrade to Update4 or later version, then try it again.
Besides, if you still want to keep your current version, you can use the VSTS Variable Tasks extension: Variable Toolbox to expand the build/release variables. (And the source code here for your reference.)
When you define a variable in the Variables screen and use other variables as value, they won't be expanded (as you may have expected). Instead the literal text is passed to the tasks in the workflow. Without this little task the following configuration won't work:
Variable Value
Build.DropLocation \\share\drops\$(Build.DefinitionName)\$(Build.BuildNumber)
By adding the Expand variable(s) task to the top of your workflow, it will take care of the expansion, so any task below it will receive the value you're after.
PS: The new agent (version 2.x) auto-expands variables now.
And this similar thread for your reference:
TFS 2015 Can build variables access other build variables?
UPDATE:
Based on your TFS version, it should be TFS 2015 update3 (You can upgrade to Update4 or later version if that's an option, also upgrade the build Agent accordingly). To check the agent version : Go Manager Server (gear icon) >> AgentPool >> Select a pool >> select an agent >> Switch to Capabilities, you will see the agent version in that page.
Related
I have a standard pipeline agent that works for CI whenever a pull request merged into master. It was working fine until I merged a pull request created by a visual-studio-2019 developed branch. Now I am getting
error CS8107: Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater.
It is working fine when I push any changes with vs2017.
What should I do to avoid this error?
P.S: I want to keep using vs2019
Thanks in advance.
This happen when you have code like the following:
MyType foo = default; // assign the default value for this type
In C# 7, the supported syntax is:
MyType foo = default(MyType);
but the simpler form was added in 7.1.
There are two ways to fix this:
Don't use the newer form. Change any existing instances of default to have a type, and change the settings so that the IDE will prefer the verbose form. Here's a picture with the new form turned on, just change the Yes to a No:
If you're using .editorconfig files, you can configure the csharp_prefer_simple_default_expression setting.
Set the language version for your project to be high enough to support the new syntax. Keep in mind that if you set it to latest it may use a different version between your development box (VS2019) and your build agent (e.g. possibly still on VS2017).
I just solved this issue by updating my Agent Pool in the build pipeline to use "Hosted Windows 2019 with VS2019"
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):
I am using default build template with TFS 2013 and want to pass the name of the person, who initiated the build, as a variable to a post build powershell script.
I know, that there are a couple of "env:TF_BUILD..." variables, that are filled during build process, but I couldn't find a variable, that holds the "user", who triggered the build.
The variable I am looking for is suppose to be something like "$BUILD_REQUESTEDFOR".
I try to put a -user "$BUILD_REQUESTEDFOR" into section 2.5 as Post-build script arguments in a build definition, but it seems, that it wouldn't be filled or interpreted.
Is there something i have missed or is there an other way to get my problem solved.
Any help appreciated.
The predefined variable "$BUILD_REQUESTEDFOR" is only available for vNext build (TFS 2015 and later version). See Build variables for details.
For xaml build, there isn't the variable to get the current user who triggered the build within the build process. See Team Foundation Build environment variables for details.
In TFS post build script of a .proj file I want to find whether the project build is happening through TFS triggered build or manually triggered build.
Can someone suggest me how to do this using macros in Post Build event.
Short answer: you can make use of the IsDesktopBuild MSBUILD property within your csproj file to differentiate between TFS and local build.
Long Answer:
Developer or Team Build?
To differentiate the build environments we have to implement a mechanism that detects in which environment the build is being executed. In other words, we need to know if we running a local build that is executed by the developer or a team build running on the build server.
In fact, there are 3 different build environments we need to consider:
· Visual Studio Build – a build executed by a developer, on their own development machine inside the Visual Studio IDE
· Team Build – a build executed by TFS (manually or scheduled), on the build.
· Desktop Build – a build explicitly executed manually, on the development workstation using the command 'msbuild.exe tfsbuild.proj'.
A ‘DesktopBuild’ and a ‘TeamBuild’ are very similar in nature except that ‘DesktopBuild’ does not perform a ‘GetLatest’ function from source repository, will not ‘Label’ the source tree and will not determine the change set.
When using MSBUILD tasks (as we will use primarily in following sections), one common way to achieve this is to use the ‘IsDesktopBuild’ and ‘BuildingSolutionFile’ properties as conditions to test in the tasks.The ‘IsDesktopBuild’ property is declared in the ‘Microsoft.TeamFoundationBuild.targets’. The ‘BuildingSolutionFile’ property is declared and assigned automatically by MSBUILD.
The following table lists the values of each of these properties in each of the build environments.
Environment IsDesktopBuild BuildingSolutionFile
Visual Studio Build (empty) (empty)
Desktop Build true true
Team Build false true
One caveat with using the ‘IsDesktopBuild’ property is that it is not defined in many target files by default. This property will have an ‘empty’ value in a Visual Studio build, so we initialize it to a value of ‘true’ as the default value. Therefore we need to be explicitly define it in all MSBUILD target files where it will be tested.
We simply add the following element to all target files where we need to differentiate between a build on the development machine and a build on the build server (within the first section).
<IsDesktopBuild Condition="'$(IsDesktopBuild)' == ''">true</IsDesktopBuild>
Update: thank you #dbardakov. Starting VS 2012 we can use the property to find if the build is happening within Visual Studio:
BuildingInsideVisualStudio
MSDN SOURCE - for BuildingInsideVisualStudio
MSDN SOURCE
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.