TFS How to GetEnvironmentVariable value - tfs

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”

Related

Using Variables in a TFS Build Template

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

Cannot receive parameter from Script content to Predefined Parameter in Jenkins

I would like to pass hostname parameter which is declared at Script Content to Predefined Parameter in Trigger/calls on build other project where my child project will receive parameter from the parent project.My code looks like this in Script Content:
`machine_name="$(hostname)"`
So in order to pass my parameter to the child project I declared:
host_name=${machinename}
in Script Content .But when I check in my child project it display as ${machinename} which is not I want .Can someone tell me what am I missing or what step that I done wrong or is there any way to perform this ?
Try using ENv Inject plugin, all you need to do is below:
Your script should contain below step:
machine_name="$(hostname)" > inject.txt
Now use Inject environment variables build step and in
property file path give inject.txt
what's the use?
By this step, now you machine_name variable holds the hostname value throughout the job.
Next, in your Parameter in Trigger/calls on build other project
host_name=${machine_name}
And use the same variable in child job.
I think there is no need for multiple assignments above, but still you can try this.
'_' was missing. host_name=$machine_name.
you cannot set or pass the parameter value from the script o/p. either make it as env variable using groovy or set in to property file & read.

TFS ConvertWorkspaceItem error

I'm trying to get Uri path from Local path of Build directory. I've added ConvertWorkspaceItem however I get an error:
What am I doing wrong?
EDIT
This is the way I've set it up. I get valid BuildDirectory (C:\builds...) and I want to get a server path (\TFSBUILDSrv\some\blah)
Result:
You need to specify valid variable names for all of these three properties. there should also be a variable declared in the workflow called workspace.
It's a type error
As ConvertWorkspaceItem.Workspace Property from MSDN mentioned, this should be a value of workspace that contains the files to convert paths for( BuildDirectory to test1)
So just need to change the variable type to workspace of the workspace variable. Everything is OK.
A example:

Updating the Jenkins Variable with a value calculated in a batch file

I am new to Jenkins. My aim is to define a build job in which I have created an environment variable suppose "x" by checking "This build is parameterized" option. I am executing a batch file which is performing a set of instructions and I want the x to be updated by a value calculated in batch file. Any suggestions how can I update the Jenkins variable value calculated using a batch file. I have tried using enviject plugin but not getting how to update the variable.
Thanks in advance
enviject plugin should be helpful here.
But - you need to update your batchfile to create a property file.
As the first step in the build action, I am passing some properties to my test.
Then, I use the property name like a parameter passed to Jenkins to execute a windows batch command. This bat file creates a result file in .properties format.
As the third step, i read the (result) property file. The result property file can have the same properties with updated values.
Now - your original proeprties would have been updated with new values & can be used in your subsequent build steps.

Pass values to Jenkins parameter from a file

I would like to know if there is an option to pass the value from a file to one of the Jenkins parameters. For eg : I have a property file called config.properties and I would like to pass the value of a field called projectName to a Jenkins parameter called Project. How can I do this ?
Use Extended Choice Parameter Plugin - it allows you to define a property file and and a key within the file to use. The plugin expects comma-separated values to allow the user to choose one but if there's only one value - it will be chosen by default.
Add the Plugin Extended choice Parameter as stated by antweisis
Need a Property files which means the file with the content in following format Eg: dates=21012,2013,2014,2015
I have added the Image with how I have Configured the jobs as shown in the image bellow.
To dynamically add the content to a property file create a script and run it as cron job or run the job that will populate the file first.
Where,
Delimiter = comma as we have comma separated the values
Propertyfile = path to the files
Propertykey = the key we have used for our example we have used dates
This will successfully create a drop down from the content of the files.

Resources