CodeMonkey CodeMonkey - 9 months ago 137
Bash Question

Teamcity - setParameter does not permanently store updated value in parameter


Need to

in Teamcity
Configuration Variable
, so I can use the value the next time the
build step
is executed.

I have set up a script:

export current_build_date_format="+%%Y-%%m-%%d"
export current_build_date="$(date $current_build_date_format)"
echo "##teamcity[setParameter name='latestDeploymentDate' value='$current_build_date']"

When I echo
in the following step, it correctly prints out for instance

But, when I go and look at the parameter's value in Teamcity, the value is still what it initially was.

I am running the script on a
build agent
that is
not on the same server
as Teamcity. Could this be the reason why I get this behavior ? Or is
not meant to store on a permanent basis ?

Thanks in advance

Answer Source

It turns out that echo "##teamcity[setParameter name='parmname' value='value']" only sets the parameter "in memory" meaning, that after the build steps run, the value will still be the same.

Instead, what you need to do to update the parameter permanently, is to use Teamcity's REST api.

To use the REST api, you will need to have a user-account that you can use from your build-script, when calling.

Here is an example of how to update a parameter, using a username/password:

export current_build_date="$(date +%%Y-%%m-%%d" "%%H:%%M)"
curl -v --request PUT -d "$current_build_date" --Header "Content-Type: text/plain" http://username:password@your-teamcity-url/httpAuth/app/rest/projects/your-build-configuration-id/parameters/latestDeploymentDate

Personally, I don't like having the username/password in the build-configuration. But it IS possible to set that up on the TC agent, so you can avoid the need to do so.