Teamcity - setParameter 不会永久存储参数中的更新值
Teamcity - setParameter does not permanently store updated value in parameter
场景:
需要在 Teamcity Configuration Variable
中 "setParameter"
,这样我可以在下次执行 build step
时使用该值。
我已经设置了一个脚本:
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']"
当我在接下来的步骤中回显 %lastestDeploymentDate%
时,它会正确打印出来,例如 '2016-11-07'
但是,当我去查看 Teamcity 中的参数值时,该值仍然是最初的值。
我是 运行 build agent
上的脚本,即 not on the same server
作为 Teamcity。这可能是我出现这种行为的原因吗?或者 'setParameter'
不是要永久存储吗?
提前致谢
原来echo "##teamcity[setParameter name='parmname' value='value']"
只设置了参数"in memory"的意思,在构建步骤运行之后,值仍然是一样的。
相反,要永久更新参数,您需要做的是使用 Teamcity 的 REST api。
要使用 REST api,您需要有一个用户帐户,您可以在调用时从构建脚本中使用该帐户。
这是一个如何更新参数的示例,使用 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
就个人而言,我不喜欢在构建配置中使用 username/password。但是可以在 TC 代理上进行设置,因此您可以避免这样做。
场景:
需要在 Teamcity Configuration Variable
中 "setParameter"
,这样我可以在下次执行 build step
时使用该值。
我已经设置了一个脚本:
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']"
当我在接下来的步骤中回显 %lastestDeploymentDate%
时,它会正确打印出来,例如 '2016-11-07'
但是,当我去查看 Teamcity 中的参数值时,该值仍然是最初的值。
我是 运行 build agent
上的脚本,即 not on the same server
作为 Teamcity。这可能是我出现这种行为的原因吗?或者 'setParameter'
不是要永久存储吗?
提前致谢
原来echo "##teamcity[setParameter name='parmname' value='value']"
只设置了参数"in memory"的意思,在构建步骤运行之后,值仍然是一样的。
相反,要永久更新参数,您需要做的是使用 Teamcity 的 REST api。
要使用 REST api,您需要有一个用户帐户,您可以在调用时从构建脚本中使用该帐户。
这是一个如何更新参数的示例,使用 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
就个人而言,我不喜欢在构建配置中使用 username/password。但是可以在 TC 代理上进行设置,因此您可以避免这样做。