passing a variable into a templates parameter - azure-devops

I have a template which has a parameter 'enableVM1' of type boolean.
Simply, I want this parameter to be set by an expression. I want this expression to resolve at runtime since the data is retrieved by an earlier step.
- stage: Build_Tenant_Refresh
displayName: "Destroying Tenant VM"
variables:
vm1ActiveFlip: $[ not(eq(stageDependencies.Shutdown_Tenant.Setup.outputs['Identify_built_VM.vm1Active'],'True')) ]
jobs:
- template: tenant-infrastructure-plan.yml
parameters:
enableVM1: <<ANY EXPRESSION WHICH I'D EXPECT TO RESOLVE TO A BOOL>>
When I press the run button on the pipeline I am immediately told that enableVM1s value is not a boolean.
This suggests that the a parameters are evaluated at parse/compile time rather than run time. Is this true?
I was intending for the expression to be: $[vm1ActiveFlip] (referencing the variable defined at the stage).
I tried lots of variants for the expression including:
$[eq('vm1ActiveFlip','True')]
$[eq('True','True')]
Is it possible to achieve what I need?

I tested enableVM1: $[eq(variables['Build.SourceBranch'],'refs/heads/main')] and reproduced your issue:
To solve this , you need to use compile-time expressions (${{ <expression> }}). This is because if you use runtime expression, then when you click the run button, the expression has not been parsed as a boolean value and is judged as a string.
In a compile-time expression (${{ <expression> }}), you have access to parameters and statically defined variables. In a runtime expression ($[ <expression> ]), you have access to more variables but no parameters.
This is stated in this document,please refer to it.
Update:
As workaround, using job output variables and introducing a dependsOn to the template. For details , please refer to this document.

Related

What is the exact meaning of `pl.col("")` expression with empty string argument

The example in a section about 'list context' in the polars-book uses pl.col("") expression with an empty string "" as the argument.
# the percentage rank expression
rank_pct = pl.col("").rank(reverse=True) / pl.col("").count()
From the context and the output I can guess what pl.col("") expression does. But the API documentation does not seem to cover a case of empty string as the argument to pl.col and I would like to know the precise meaning in this use case. Any helpful answer is greatly appreciated!
The precise meaning is to act as a 'root' Expression to start a chain of Expressions inside a List context, i.e., inside arr.eval(....). I'll need to take a step back to explain...
'Root' Expressions
In general, only certain types of Expressions are allowed to start (or be the 'root' of) an Expression. These 'root' Expressions work with a particular context (select, filter,with_column, etc..) to identify what data is being addressed.
Some examples of root Expressions are polars.col, polars.apply, polars.map, polars.first, polars.last, polars.all, and polars.any. (There are others.)
Once we declare a "root" Expression, we can then chain other, more-generic Expressions to perform work. For example, polars.col("my_col").sum().over('other_col').alias('name').
The List context
A List context is slightly different from most contexts. In a List context, there is no ambiguity as to what data is being addressed. There is only a list of data. As such, polars.col and polars.first were chosen as "root" Expressions to use within a List context.
Normally, a polars.col root Expression contains information such as a string to denote a column name or a wildcard expression to denote multiple columns. However, this is not needed in a List context. There is only one option - the single list itself.
As such, any string provided to polars.col is ignored in a List context. For example, from the code from the Polars Guide, this code also works:
# Notice that I'm referring to columns that do not exist...
rank_pct = pl.col("foo").rank(reverse=True) / pl.col("bar").count()
Since any string provided to a polars.col Expression will be ignored in a List context, a single empty string "" is often supplied, just to prevent unnecessary clutter.
Edit: New polars.element expression
Polars now has a polars.element expression designed for use in list evaluation contexts. Using polars.element is now considered idiomatic for list contexts, as it avoids confusion associated with using col(“”).

Passing Parameter to Data Flow in Azure Data Factory

I have a data flow which takes startTime and endTime as parameters and I am passing the values to these parameters via a pipeline using pipeline expression but the expression is not evaluated rather its considered as string. Attached the Images
I found out the root cause,
long() is not supported in expression builder.
# is missing at the beginning of the expression.
So the working expression was which gives CURRENT EPOCH TIME
#div(sub(ticks(startOfDay(utcNow())),ticks('1970-01-01T00:00:00.0000000Z')),10000000)

ADF: Dynamic Content in parameters

I am trying to pass text with dynamic content as a parameter into a pipeline (execute pipeline activity).
As a super simple example, I want the input to my pipeline to be a timestamp, utcnow(). Here are my results:
I've noticed:
If I put #utcnow() in a set variable activity and set the execute pipeline parameter to that variable it works.
If I put #utcnow() (or #{utcnow()}) in the main parameter and set the execute pipeline parameter to that parameter it does not work. I get that string "utcnow()" as the result.
Is there anything that I am missing here? I definitely feel like I've done this successfully before.
If I understand your question correctly, the issue is caused by the main parameter(pipeline parameter) doesn't support expression or functions.
For example, we could pass the value from variable to pipeline active parameter, and it works well, because variable support expression/functions:
When the main pipeline only contains an Execute Pipeline active, we pass the value from main parameter(pipeline parameter) to the Execute Pipeline parameter:
When we debug the pipeline, we need pass the value of main parameter:
The value of pipeline parameter only support the String value, then function utcNow() or #{utcnow() will considered as the String.

how to pass in an expression through a parameter

Suppose I have a foreach inside of a pipe:
I'd like to iterate through the following:
#split(split(item().name,'_')[4],'-')[1]
However, I'd like to pass this formula in through a parameter.
I've defined a parameter myExpression with the desired value in the pipeline, and attempting to reference it like so:
Note that the full expression would be: {#pipeline().parameters.myExpression}
However, data factory does not execute that expression, rather it just accepts it as a verbatim string:
{#pipeline().parameters.myExpression}
How do we pass in an expression from parameters from within the pipeline?
When you define a parameter like this and pass the value, what you are doing is is send a string input, as the textbox doesn't accept expression. The only way to pass expression to a parameter is to pass it from another pipeline. Another issue we have is one ADF limitation - there can not be nested iterations. Calling a second pipeline solves both the issues.
Split your flow in two pipelines.
First (parent) pipeline - Keep all steps up until generating the array over which iteration has to happen.
#split(split(item().name,'_')[4],'-')[1]
Then, inside a for each loop, invoke an "Execute pipeline" activity. In there, pass the expression that you desire in a similar fashion-
In the child pipeline, define a string parameter to absorb the passed value. Then, use #pipeline().parameters.ParamName to use it in there.
HTH
your description lacks a lot of context of what are you trying to do. I can only presume that you generate array in one pipeline and you want to iterate it in another. Looking at your print screen it looks like you typed in your value, therefore output is a plain text. you should hit dynamic context
so it would look like this:

Azure DevOps: Version variable type

What is the syntax to perform type casting for variables in Azure DevOps?
This article - https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=vsts - suggests there's a "Version" type and mentions a function which would interpret it as a string would resolve it in major.minor.build format but how do you infer a variable as a "Version" type in the first place? And how do you pull out the individual aspects (i.e. major, minor, build, etc.) from it?
If you look at the types definition, you can see that the type can be guessed by the notation. For instance, if it's wrapped in '', it is a string. Or, if it starts
with a number and contain two or three period (.) characters
it is of type Version.
Regarding the typecasting, it says that Version.TryParse is used. So, if you read this variable in e.g. PowerShell and try to case to Version type, I would expect it to work.