How to reference a variable within a variable in VSTS vNext build definition? - tfs-2015

How is it possible to reference a variable within a variable in the new scripting system of VSTS?
e.g:
RemoteMachineFqdn: somemachinename.somedomain
RemoteMachineUncPath: \\$(RemoteMachineFqdn)\c$\
In the aforementioned example, assume there are tasks that both use CMD and Powershell scripts with the given variables. I tried using the the variables by referencing their values from the environment but it does not work for both scenarios since %variable% works only in CMD and $env:variable - only in Powershell.
What is the standard way to do it?

What you are looking for is Logging Commands. To invoke a logging command, simply emit the command via standard output. For example, from a PowerShell task:
##vso[task.setvariable variable=testvar;]testvalue
This example sets a variable in the variable service of taskcontext. The first task can set a variable, and following tasks are able to use the variable. The variable is exposed to the following tasks as an environment variable.

Related

In jsr352 batch job xml, how to read/inject a environmental variable from system

I have environmental variable called ENV, which holds the DEV,QA OR PROD region as value. When the server.xml loaded it includes the corresponding db configuration using this variable. For ex: db-config-${env.GAH_ENV}.xml
I would like to pass the same value to the batch job xml as a job parameter or properties to any of the class. How Can I do that.
below code snippet not working
<property name="environment" value="${env.GAH_ENV}"/>
The short answer is that using a batch property may not be a good solution and you might consider something else like MicroProfile's #ConfigProperty.
The reason is there's not a built-in way to access environmental variables through JSL substitution. There is also not a convenient way for one artifact to set a property value to be used by a second artifact running later within the job execution.
In the special case that you are starting the job from within the same JVM it will execute, of course, you could pass the env var value as a job parameter.
But in the general case, if you can change the Java code and you don't really need a batch property I would use a MicroProfile Config property instead, injected via #Inject #ConfigProperty.
By doing so you lose the batch-specific substitution precedence, including the override available via job parameters passed with the submit/start. You also give up the ability to use this property in other JSL substitutions (to "compose" its value into other batch properties via other substitutions).
But you at least get a property with its own various levels of precedence/override (e.g. server config, env var, microprofile-config.properties), which is more flexible than just always reading the env var via System.getenv( ).
This is certainly an area to consider for the next version of the (now-Jakarta) Batch spec.

Pentaho variables at JVM level

Using set variables step in pentaho, I have defined a variable and the scope is set to "valid in the Java virtual machine", but it is not replacing in one of the sql's used in the table input step.
Table input step is checked with option "replace variables in script". But the same variable when I placed in kettle.properties file, it is working. Pentaho job available in the repository and running from Linux box
Could anyone please share your thoughts?
You can-not set the parameter and use it in the same transformation, because it executes all the steps parallelly.
Logic-wise correct approach is first set the variable and get the variable in next transformation and further use or replace in respected steps.
As Working Hard.. says, you can not use a parameter in the same transformation, you have to use another transformation after setting the variables.

TFS 2015 Build Variable Expansion

We have a VNext build definition, on the Variables tab we have added a few custom variables. In one of the variable values we refer to another variable, i.e.
FileDescription = $(Build.DefinitionName)
However it appears that when we reference it in a PowerShell script the FILEDESCRIPTION environment variable exists but the value is not expanded(it contains "$(Build.DefinitionName)" ) and is treated as a string literal.
The documentation appears to suggest that we should be able to refer to it and it will be subsituted at run-time -
https://msdn.microsoft.com/en-us/library/vs/alm/build/scripts/variables
Is there a way to get TFS to automatically expand the variable at runtime?
In vNext build, it seems not expanded the variable everywhere.
For example, in MSBuild-Arguments, /p:OUTPUT="$(FileDescription)" is expanded to /p:OUTPUT="(the name of build definition)" , but in powershell it will only prints "$(Build.DefinitionName)" directly.
Try to use below Workaround: Try to use the corresponding generated environment variables (for example $env:Build.DefinitionName).
$FileDescription = $env:Build.DefinitionName
Note: If you need to change the path, you have to change the PS script instead of a build variable.

Powershell commands variables return empty in ps1 script

I'm trying to simply get some data into a variable (this s just an example of my issue, much bigger script in the works),
$var=get-physicaldisk
This works if I type it out in powershell, but if I try to script is with ps1 the variables never get filled. one method Ive used for other variables because of this was the set-variable, but this cant seem to be used in conjunction with a get command.
If you are trying to get the $var to show up after the script is complete, use this formatting. BEWARE!-- the variables will continue to exist in that powershell session until it is closed
$global:foobar=get-process
You can also use $script:foobar=get-process to have the variable persist throughout the script (within functions and loops)

Declaring a variable for use in a Build Process

I am using a custom build process template and I am trying to declare a variable that can be used to populate the default in an argument, but I'm having some problems and I think it's simply because I don't quite understand how XAML and the build process use variables.
For ease of explanation (because our build process is terribly complex) here is what I'm looking at:
Process Begin
Run On Agent
Initialize Variables
If RunTests = True Then
Establish a Connection to SQL
Run SQL
Run Tests
Email User with Results
Else
<Do Other Things>
End If
Finish Build
Process End
I'm trying to use the XAML editor built in to VS2012 (although I'm open to switching if there's a better IDE, I have to add a lot of stuff to this template). So I'll click on the Run On Agent node and click on the Variables section to create a variable called SQLServername. This variable is supposed to be populated by the SqlServerHostName argument that is part of the Build Definition. So SQLServername's default value is SqlServerHostName. No problem there, I think.
However, I then try to add a new argument: ConnectionString which defaults to "Server=" & SQLServername & ";database=master;integrated security=sspi", and the compiler error:
SQLServername is not declared
Occurs. I'm sure I am misunderstanding variables and how they're used within this thing, but what should I be looking for?
It turns out that I was misunderstanding the scope of the variable declaration. I simply left the ConnectionString as a string that the user can modify, which works for our purposes.