I'm trying to generate a name for a NuGet package in an Azure DevOps YAML pipeline.
The context is creating packages on each automated build with the name of the package, the name of the branch, the date and the incrementing revision number.
packageName-branchName-year-month-day-revision
This way when a new feature branch is created it will generate a unique package which can be used for testing in projects which need it.
I'm struggling to set a variable in the YAML file from environmental variables such as the date or revision number.
Using the ##vso command I'm able to set 'myVariable' to hello and print it out.
- script: |
echo '##vso[task.setvariable variable=myVariable]hello'
- script: |
echo my variable is $(myVariable)
When I try setting the variable from PowerShell as below I get the following error '#$dateStr' is not recognized as an internal or external command'.
# Create a variable
- script: |
#$dateStr = (Get-Date).ToString('yyyy-MM-dd')
echo '##vso[task.setvariable variable=myVariable]#$dateStr'
# Print the variable
- script: |
echo my variable is $(myVariable)
When I try to set a variable in the variables section of the YAML file as so.
variables:
solution: '**/*.sln'
foo: $(Date:yyyyMMdd)
- script: |
echo my variable is $(foo)
The variable is not interpolated and it outputs as.
'my variable is $(Date:yyyyMMdd)'
How do I create variables based on environmental variables such as $(rev) and $(Date)?