Using Variables in a TFS Build Template - tfs

We created a build template that accepts the path of a powerscript filename as an argument. Right now it works if I type in the actual path of the script. I would like to pass $(SourceDir) as part of the path, and then replace it with the actual value during the build.
For example: $(SourceDir)\myapp\scripts\scripttorun.ps
Here are the steps that I have done:
In the template I have created a variable named DeploymentScript
Then ConvertWorkspaceItem DeploymentScript -> DeploymentScriptFilename
Then pass DeploymentScriptFilename as an argument to PowerShell

Possibly duplicate with this case TFS How to GetEnvironmentVariable value. You can't use $TF_BUILD_BUILDDIRECTORY in a custom build process.
Refer to the last paragraph in this MSDN document:
Use environment data from a custom build process
If you need to use an environment variable in your custom build
process template, you can use the GetEnvironmentVariable activity to
get the data. You can get data from any of the
WellKnownEnvironmentVariables.
For example, to get the path to the binaries directory, set the Name
property of the GetEnvironmentVariable activity to
Microsoft.TeamFoundation.Build.Activities.Extensions.WellKnownEnvironmentVariables.BinariesDirectory
Please refer more detailed info about how to use it from this blog Using Environment Variables in Visual Studio 2013 and TFS 2013

Related

TFS Build Template Customization ( MSBuildArguments)

I have to customize TFS DefaultTemplate.xaml with MSBuildArguments Parameter.
Once we try to create new XAML build definition & select default template, once it gets loaded then I want to set code MSBuildArguments in Advance setting & parameter should be /p:DebugType=pdbOnly;Configuration=Release by default.
As of now this Arguments we have to put manually whenever we create a new build definition. I want to make it customize this template.
screen shot:
Specify MSBuild Arguments when create a build definition or queue a build is more convenient.
However if you want to bind the arguments with the xaml build template, then you need to custom the template.
In your scenario, you can simply replace the value of CommandLineArguments with below strings: (Note that the arguments you added here will be hidden, that means you can not see them in build definition, they are set to be the default arguments)
String.Format("/p:SkipInvalidConfigurations=true {0}", "/p:DebugType=pdbOnly;Configuration=Release").
But same time the MSBuildArguments you specified in build definition will not be available any more.
You can reference below articles to custom the build template to replace the MSBuildArguments:
Pass Relative Path Arguments to MSBuild in TFS2010 Team Build
Properly incorporate MsBuild arguments into your build process
template

publish junit test result report from parent's workspace

I have a parent job and two child jobs in jenkins. The workspace shared by the child jobs resides within the parent job.
Now the child jobs are producing a Junit RspecFormatted logs (job1.xml and job2.xml), which is getting stored in the parent's job workspace.
I am trying to refer giving the full path:
$JENKINS_HOME/workspace/{parent-job}/{folder a}/{folder b}/{folder c}/test-results/job1.xml in the post build result section but the build fails to find this path.
Note: I am able to print the file in the Execute Shell section with this path
I'm not really sure about the issue, can you give me more details?
By the way if i understood your needs, you can use the:
https://wiki.jenkins.io/display/JENKINS/Parameterized+Trigger+Plugin
To get variables like TRIGGERED_JOB_NAME and NUMBER, so you can build the PATH
$JENKINS_HOME/workspace/${TRIGGERED_JOB_NAME}/{folder a}/{folder b}/{folder c}/test-results/job1.xml
What about folder a/b/c, where are these variable valued?
You can also simply pass these information as parameters and than use them as variables to dynamically build the path...
Let me know if it's clear and if it helped...

TFS How to GetEnvironmentVariable value

In my tfs build I've created an argument to which I pass in $(TF_BUILD_BUILDDIRECTORY)
Then in my xaml file I've added a variable called "test1" and added GetEnvirenmentVariable" step where I would like to store value of
TF_BUILD_BUILDDIRECTORY
I can NOT get the value to come through. Output from my build:
It prints $(TF_BUILD_BUILDDIRECTORY) instead of "C:\temp... etc"
Please help!
thanks
Refer to the last paragraph in this MSDN document:
Use environment data from a custom build process
If you need to use an environment variable in your custom build
process template, you can use the GetEnvironmentVariable activity to
get the data. You can get data from any of the
WellKnownEnvironmentVariables.
For example, to get the path to the binaries directory, set the Name
property of the GetEnvironmentVariable activity to
Microsoft.TeamFoundation.Build.Activities.Extensions.WellKnownEnvironmentVariables.BinariesDirectory
Please follow the below steps:
Create a String variable named: BINARIESDIRECTORY.
Add GetEnvironmentVariable (String) activity, set Name = Microsoft.TeamFoundation.Build.Activities.Extensions.WellKnownEnvironmentVariables.BinariesDirectory
and Result = BINARIESDIRECTORY
Add CopyDirectory activity, set Source = BINARIESDIRECTORY and
Destination = “\servername\drop”

How can I get value "RequestedBy" in tfs 2013 build?

In tfs 2010 build, it's easy to get that vale using "BuildDetail.RequestedBy". what's the equivalent in TFS 2013? I couldn't find "BuildDetail" even.
It's still build detail. However, in the new templates a lot of the complexity is hidden by default. Use the GetBuildDetail activity to retrieve the variable you need.
Thank you MrHinsh
It's very good suggestion!! Really appreciated!!
The value of "RequestedBy" is actually required by powershell that need to be invoked at later stage to log people name whoever trigger the build.
The following steps are what I've done to make "RequestedBy" value available in powershell script:
In TfvcTemplate.12.xaml, create variable "myBuildDetails".
Drag "GetBuildDetail" into template and specify "myBuildDetails" as result of it.
Modify "Run optional script after Test Runner" property "EnvironmentVariables", set it's value to "New Dictionary(Of String, String) From {{"RequestedBy", MyBuildDetails.RequestedBy}}"
In my ps1, the value can be retrieved by "$Env:RequestedBy"
It's not perfect solution, but it's working.
Instead of modifying build template,I though if we could inject expression something like "$(myBuildDetail.RequestedBy)" from script argument of build definition would be much tidy solution.

How does TFS's convertworkspaceitem work?

I'm trying to follow the instructions for deploying a database via TFS build listed here:
http://www.mytechfinds.com/articles/software-testing/6-test-automation/64-db-deployment-tfs
The instructions include notes about how to configure a ConvertWorkspaceItem element. I've followed the directions, but TFS remains unhappy with my setting for 'Result' and 'Workspace'. For now, I simply entered the text from the directions ('dbproj' and 'Workspace', respectively). TFS complains about my values:
Compiler error(s) encountered processing expression "dbproj". 'dbproj' is not declared. It may be inaccessible due to its production level.
I'm trying to find basic tutorial information on the ConvertWorkspaceItem element, but other than the MSDN reference page there isn't a lot of info. Does anyone know much about configuring this element?
You need to specify valid variable names for both of these properties. there should already be a variable declared in the workflow called workspace, You will need to declare a variable of type string that you wish to receive the result of this activity and specify it's name as the Result property. It looks like in your linked article the author must have already created a variable called dbproj. At the bottom of the workflow designer is a variables tab where you can define your own variables.

Resources