Teamcity SetParameter doesn't seem to be working - deployment

As the first step in a build configuration I am trying to dynamically change a parameter and use it in the subsequent steps. Reading online, it seems that the way to do this is to call ##teamcity[setParameter. But this doesn't seem to be working. It doesn't even change the value in the same step.
For example, I have created a test parameter and set it's default value to '1'. Inside a powershell script, I tried to change it to 2, as shown below.
But the output remains unchanged as can be seen below
I am currently using TeamCity 8.0.3 (build 27540). What am I doing wrong?

EDIT: I think the problem might be the command you're using to set the parameter. Try:
Write-Host "##teamcity[setParameter name='TestParameter' value='2']"
--
We've experienced the same behavior. The key here is 'subsequent steps.' You must modify the parameter in a separate build step that is run before the step in which you want to use the new parameter.
It's my understanding that all parameters in a build step are evaluated immediately before the execution of that step. The tokens will be replaced with the unmodified values of those parameters. Thus, what actually gets executed by the build agent is:
Write-Host "TestParameter value is 1"
Write-Host "##teamcity[setParameter name='TestParameter' value='2']"
Write-Host "TestParameter value is 1"

Related

TeamCity and PowerShell dont assigns a value to a variable

I'm studying team city, and it's just a wonderful thing! However, I have an env.versionReleas to which a value should be assigned in the PowerShell script, but not assigned. The script is quite simple
$sss="afaf"
Write-Host "##teamcity[versionReleas name='env.versionReleas' value='$sss']"
and this variable remains empty. What am I doing wrong?
TeamCity: 2021.1.1 (build 92714)
Spes settings env did not give anything. It seems that Team city does not respond to my message. The answers that are on the site do not help. The value remains empty, just as it was empty

Azure DevOps - Can we reuse the value of a key in the same variable group?

I have lots of URL values and their keys. But there is no way to batch import the variables and the "value" controls are also not text boxes in the Variables Group page to perform chrome browser extensions assisted find and replace.
If this is possible, what is the syntax to refer to the key?
As in, I have a variable App.URL : www.contoso.com.
I am using the key to substitute value in my next variable like this Login.URL : $(App.URL)\Login and this doesn't work.
GitHub link : https://github.com/MicrosoftDocs/vsts-docs/issues/3902#issuecomment-489694654
This isn't currently available, not sure if it will be. Can you create a task early in your pipeline that sets the variables you need in subsequent tasks/steps? This gives you more control as you can store the script along with your source. You could then use a pipeline variable for the environment you're in and let your script use that to set values appropriately.
See Set variables in scripts in the MS docs.
If it's not possible to re-architect your app to concatenate the url strings in the application, what the previous commenter said about creating a simple script to do that for you would be the way to go. Ie:
#!/bin/bash
#full login url
fullLoginUrl=$APP.URL\$LOGINSUFFIX
echo "##vso[task.setvariable variable=Login.URL]$fullLoginUrl
Otherwise, perhaps playing around with the run time vs compile time variables in YAML pipelines might be worth trying.
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#understand-variable-syntax

How to reset VSTS counter?

We have a need to reset VSTS counter. I do not see any way to do this through UI. There is a way to do it by directly invoking reset build counter REST API, but in order to do this, you need to know the counter id, which you should be able to find out by invoking get a definition REST API. Unfortunately, no matter what I do get a definition call does not return build definition counter.
What am I missing?
Scott Dallamura from Microsoft wrote this thread:
the counters feature was experimental and removed back in March of
this year. I'm not sure how it even got into the documentation, but
I'll make sure it gets cleaned up.
I also didn't success to get the counterId in an API call.
At workaround, you can reset the revision of the build number if you change the build definition name, you can just add/remove a character.
Instead of trying to reset the counter variable, you could create a new variable with a GUID prefix.
This solution creates duplicate counters which might not be ideal but this gives you the ability to revert back to the previous counter values, if necessary.
Please see the following YAML code snippet
variables:
...
#Change this Guid if you require a reset seed on the same value.
resetCounterGuid: 'efa9f3f5-57fb-4254-8a7a-06d5bb365173'
buildrevision: $[counter(format('{0}\\{1}',variables['resetCounterGuid'],variables['YOUR_DEFINED_VARIABLE']),0)]
...

Is it possible to manually update the build variable $(Build.BuildId)

I am helping a friend with their VSTS build and we are using both build identifiers
$(Build.BuildId)
$(Build.BuildNumber)
This is specific to a Xamarin.iOS build where we are using the new VSTS Build tasks for updating the Info.Plist. We need to use the $(Build.BuildId) for the version code which is just a number that increments. Then we want to use the $(Build.BuildNumber) for the actual Version Name. If was to format this into the build string it would look like this:
$(Build.BuildNumber) = 1.0.0
$(Build.BuildId) = 148
Result = 1.0.0 (148)
The problem is we have already submitted our app to the app store with a larger build ID then what our current build is at. Instead of running the build X number of times to sync it up we would like to manually update the BuildId so we can start using this for our full workflow.
No, it’s impossible.
The predefined variable Build.BuildId value is unique to record echo build in the VSTS account.
Even you can change the value by logging command, but it can only work for the current build, when you queue next the build, the build ID will continue increased without any effect.
Such as current Build.BuildId is 148, even if you use the value to 100 by Write-Host "##vso[task.setvariable variable=Build.BuildId]2148" in a build, but when another build is queued, the Build.BuildId will be 149.
The work around is using a user defined variable instead Build.BuildId:
Add a user defined variable such as custom.BuildId and set the value with ($(Build.BuildID)+GapNumber).
Such as if the current Build.BuildID is 148, while the build ID you submitted in app store is 2148, so you can use the custom.BuildId with the value ($(Build.BuildID)+2000). Then use the variables $(custom.BuildId) and $(Build.BuildNumber) for your app.
For next build. The custom.BuildId value will be 1149.
I'm using the counter expression:
MyAppVersion $[counter('my-counter-prefix', 500)]
With MyAppVersion being 500, 501, 502...
This function can only be used in an expression that defines a variable. It cannot be used as part of a condition for a step, job, or stage.
Evaluates a number that is incremented with each run of a pipeline.
Parameters: 2. prefix and seed.
Prefix is a string expression. A separate value of counter is tracked for each unique value of prefix
Seed is the starting value of the counter
You can create a counter that is automatically incremented by one in each execution of your pipeline. When you define a counter, you provide a prefix and a seed.
This is not possible to update Build.BuildId but you can set Build.BuildNumber as it is shown here using logging commands:
Write-Host "##vso[build.updatebuildnumber]my-new-build-number"

TeamCity checkbox parameter

I am looking to implement a flag to make sure no one tiggers a job by mistake.
I have added a parameter which prompts before the the job is triggerd.
An command line build step is created with the following script:
IF %ConfirmationCheck% == "false" exit 1;
No matter what setting the confirmation box has, it always starts the rest of the steps.
Anyone an idea?
Thx
I'm using powershell to do the same thing
if ("%ConfirmPrompt%" -eq "false")
{
Write-Host "Error: Confirmation checkbox was not checked"
exit 1
}
Make sure that you edit the parameter and set the un/checked value, mine are set to false/true respectively.