Reputation:
Scenario:
Need to "setParameter"
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 %lastestDeploymentDate%
in the following step, it correctly prints out for instance '2016-11-07'
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 'setParameter'
not meant to store on a permanent basis ?
Thanks in advance
Upvotes: 1
Views: 1692
Reputation:
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.
Upvotes: 3