Continuous integration 作为TeamCity中的构建步骤或依赖项重新启动代理

Continuous integration 作为TeamCity中的构建步骤或依赖项重新启动代理,continuous-integration,teamcity,Continuous Integration,Teamcity,在TeamCity中构建作业期间,是否有方法重新启动代理计算机,如何实现? 我尝试使用“shutdown-r-f-t0”添加依赖项作业或生成步骤,但TeamCity报告生成已被取消,因为它在重新启动并导致另一个代理接管生成之前无法与代理通信 单击重新启动时,将显示确认弹出窗口。当我使用Curl时,我找不到实际的链接。如何单击确认链接?看起来一样 curl -u username:password "http://TeamCityServerURL/agentDetails.h

在TeamCity中构建作业期间,是否有方法重新启动代理计算机,如何实现? 我尝试使用“shutdown-r-f-t0”添加依赖项作业或生成步骤,但TeamCity报告生成已被取消,因为它在重新启动并导致另一个代理接管生成之前无法与代理通信

单击重新启动时,将显示确认弹出窗口。当我使用Curl时,我找不到实际的链接。如何单击确认链接?看起来一样

          curl -u username:password "http://TeamCityServerURL/agentDetails.html?id=2&agentTypeId=3&realAgentName=ip_10.0.0.1"


           wget –method POST "http://TeamCityServerURL/agentDetails.html?id=2&agentTypeId=3&realAgentName=ip_10.0.0.1" –http-user=Username –http-password=password –header="Content-Length: 0" -O - -S  

以下是TeamCity问题跟踪程序中的相关请求:。
自9.0以来,可以使用“代理详细信息”页面上的“重新启动代理计算机”链接从UI手动重新启动代理。作为解决方法,您可以通过模拟从UI手动调用操作时发送的浏览器请求,从构建脚本重新启动代理。

我可以使用以下curl请求重新启动代理。但是我不知道 如何获取代理的ID列表。你是怎么得到AgentID的

         curl -u User:Password -X POST "http://MyTeamCityServerURL/remoteAccess/reboot.html?agent=2&rebootAfterBuild=true"

我们有一个类似的要求,在MacOS上定期重置USB堆栈,因为Mac的USB堆栈不可靠(Android设备与Linux或Windows完美配合)

我们有一项先决任务,包括以下选项:

  • 在同一代理上运行构建
  • 依赖项失败:使生成无法启动
  • 启动失败/取消依赖项:生成启动失败
运行“shutdown-r now”并立即使用“echo#teamcity…”系统向服务器报告成功,试图捕获实际启动的重新启动与发送到服务器的echo之间的小时间间隔

不幸的是,当TeamCity尝试在代理上启动新作业时,脚本完成和代理实际重新启动之间的时间很短,因此我们有大量中止的构建—它们被重新启动,因此它们不会完全破坏任何东西,但会将日志弄得乱七八糟

我们尝试将其替换为以下内容,将代理标记为重新启动,然后将shutdown命令委托给后台任务,该任务在发出shutdown之前等待TeamCity任务完成:

echo "Running: '/sbin/shutdown -r shortly'"
echo rebooting=yes >> $HOME/buildAgent/conf/buildAgent.properties

CONFIG_PROPERTIES=$(grep teamcity.configuration.properties.file $TEAMCITY_BUILD_PROPERTIES_FILE | cut -d= -f2)
TC_SERVER=$(grep teamcity.serverUrl $CONFIG_PROPERTIES | cut -d= -f2)
BUILD_ID=$(grep teamcity.build.id $CONFIG_PROPERTIES | cut -d= -f2)
STATUS=$( echo "${TC_SERVER}/guestAuth/app/rest/builds/id:${BUILD_ID}"|tr -d \\ )
echo Polling $STATUS in background until parent task cannot be confirmed still running.

((
  while true; do
    sleep 5
    if curl -s $STATUS | xmllint --xpath "//build/@running" - | grep true ; then
      :
    else
      echo "passw0rd" | /usr/bin/sudo -p "" -S /sbin/shutdown -r now
    fi
  done
) 2>/dev/null >/dev/null &)&
我在机器的重新启动过程中添加了一个步骤,以便在代理启动之前的某个时间点删除“rebooting”参数。(这是一个Mac,所以我在/Library/LaunchDemon中添加了一个plist

/usr/bin/sed -i~ -e /rebooting=yes/d /Users/qa/buildAgent/conf/buildAgent.properties
通过精心设计的日志文件目录,使其可写入相应的用户-否则plist将以静默方式失败…)

不幸的是,TeamCity似乎没有注意到新9.1版本中的“rebooting”参数,因此我们不得不在这个重新启动步骤和实际任务之间添加一个额外的依赖项:这个新任务只是等待,直到它在配置文件中看不到“rebooting”参数,并且有一半的时间它被取消并重新调度-这很好,因为它将“取消”消息保留在主构建日志之外,这就是我们想要的:

echo This task runs after the reboot script, as a buffer between the reboot script and the real reboot.
echo That is, THIS task will get all the INTERRUPTED errors, not the real scripts.

echo Uptime:
uptime

echo Infinite loop until machine reboot, unless reboot is already complete:
while grep rebooting=yes $HOME/buildAgent/conf/buildAgent.properties; do
  echo $(date) Awaiting reboot to interrupt task and clear rebooting=yes from buildAgent.properties file.
  sleep 15
done

显然,复制buildAgent.properties文件,然后将副本移动到原始文件的顶部,会使9.x代理注意到更改,从而无需执行此中间步骤,只要以下生成任务知道等待引导过程删除“rebooting=yes”参数。我还没有尝试过,但那肯定会更好。

我需要重新启动(非云)构建代理,作为构建的最后一步;由于生成在代理上安装了需要重新启动的软件

但是,它是一个Windows构建代理,因此必须在PowerShell中或作为批处理脚本来执行此操作

使用TeamCity 9.x和我能够构建一个简单的两行PowerShell构建步骤

第一个请求获取运行生成的代理(安装软件的代理)的代理Id。第二个请求使用相同的代理Id重新启动代理

身份验证凭据是构建的配置参数,用户名和密码值可以对TeamCity进行httpAuth

由于获得了正确的授权头,并使用了
[System.Net.WebRequest]

$username=“%buildAgentAccessUser%”
$password=“%buildAgentAccessPassword%”
$authInfo=$username+“:”+$password
$authInfo=[System.Convert]::ToBase64String([System.Text.Encoding]::Default.GetBytes($authInfo))
$uri=“%teamcity.serverUrl%/httpAuth/app/rest/agents/name:%teamcity.agent.name%/id”
$webRequest=[System.Net.webRequest]::创建($uri)
$webRequest.Headers[“授权”]=“基本”+$authInfo
$webRequest.PreAuthenticate=$true
[System.Net.WebResponse]$resp=$webRequest.GetResponse();
$rs=$resp.GetResponseStream();
[System.IO.StreamReader]$sr=新对象System.IO.StreamReader-argumentList$rs;
[string]$id=$sr.ReadToEnd();
写入输出“重新启动代理ID:$ID”
$uri=“%teamcity.serverUrl%/httpAuth/remoteAccess/reboot.html?代理=$id&rebootAfterBuild=true”
$webRequest=[System.Net.webRequest]::创建($uri)
$webRequest.Headers[“授权”]=“基本”+$authInfo
$webRequest.PreAuthenticate=$true
[System.Net.WebResponse]$resp=$webRequest.GetResponse();
$rs=$resp.GetResponseStream();
[System.IO.StreamReader]$sr=新对象System.IO.StreamReader-argumentList$rs;
$sr.ReadToEnd();
这是我的最后一个构建步骤,在构建完成后重新启动代理。

基于解决方案,只需将请求方法设置为post

$ErrorActionPreference = "Stop"
$auth = "%username%:%password%"
$auth = [System.Convert]::ToBase64String([System.Text.Encoding]::Default.GetBytes($auth))
$uri = "%teamcity.serverUrl%/httpAuth/app/rest/agents/name:%teamcity.agent.name%/id"
$request = [System.Net.WebRequest]::Create($uri)
$request.Headers["Authorization"] = "Basic " + $auth
$request.PreAuthenticate = $true 
[System.Net.WebResponse] $response = $request.GetResponse();
[System.IO.StreamReader] $streamReader = New-Object System.IO.StreamReader -argumentList $response.GetResponseStream();
[string] $id = $streamReader.ReadToEnd();
Write-Output "Trigger reboot of Agent ID: $id"
$uri = "%teamcity.serverUrl%/httpAuth/remoteAccess/reboot.html?agent=$id&rebootAfterBuild=true"
$request = [System.Net.WebRequest]::Create($uri)
$request.Method="POST"
$request.Headers["Authorization"] = "Basic " + $auth
$request.PreAuthenticate = $true 
[System.Net.WebResponse] $response = $request.GetResponse();
[System.IO.StreamReader] $streamReader = New-Object System.IO.StreamReader -argumentList $response.GetResponseStream();
[string] $response = $streamReader.ReadToEnd();

重新启动代理机器有什么意义?它是构建的一部分还是应该在最后进行清理?虚拟机必须重新启动才能加入AD域,它必须从中收集构建信息代理是云上动态配置的虚拟机,映像不能预加入,加入需要windows操作系统上的电源循环。我偏离了ur-1,这回避了一个问题,它在做什么,它需要在域上运行构建?这有什么关系!!!它必须收集信息!同步代码!并发布工件!在里面