shell脚本执行后,Gocd任务失败

时间:2018-05-05 17:38:10

标签: shell continuous-deployment go-cd

在Windows服务器上运行GOCD服务器,在Windows 10上运行代理。管道中的任务之一是使用GOCD任务中的自定义命令在代理中运行shell脚本。

截至目前,shell脚本只有1行

echo "hello"

触发任务时脚本执行正常,但管道控制台中的任务失败。

更新: 我的管道配置文件触发sh文件。内容与单行echo命令相同。

<?xml version="1.0" encoding="utf-8"?>
<cruise xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="cruise-config.xsd" schemaVersion="106">
  <server artifactsdir="artifacts" agentAutoRegisterKey="270fb4b6-d548-435b-a4b5-a6f6952e1a4d" webhookSecret="eba9b673-0757-4577-807d-82dca985d17f" commandRepositoryLocation="default" serverId="359f16bd-f9c9-4c52-bd78-081df4069961" tokenGenerationKey="82d73c79-47f7-494e-9ec7-76639d4ec961" />
  <pipelines group="defaultGroup">
    <pipeline name="test1">
      <materials>
        <git url="http://infygit.ad.infosys.com/Mohit_Vora/InfyBankH2Dev.git" dest="codedev" />
      </materials>
      <stage name="defaultStage">
        <jobs>
          <job name="defaultJob">
            <tasks>
              <exec command="mvn clean install" workingdir="codedev">
                <runif status="passed" />
              </exec>
            </tasks>
            <artifacts>
              <artifact type="build" src="codedev/target/*.war" dest="deployWar" />
              <artifact type="build" src="codedev/tomcat.sh" dest="deployWar" />
              <artifact type="build" src="codedev/tomcat.bat" dest="deployWar" />
            </artifacts>
          </job>
        </jobs>
      </stage>
    </pipeline>
    <pipeline name="test2">
      <materials>
        <pipeline pipelineName="test1" stageName="defaultStage" />
      </materials>
      <stage name="defaultStage">
        <jobs>
          <job name="defaultJob">
            <tasks>
              <fetchartifact srcdir="deployWar" dest="warTestDeploy" pipeline="test1" stage="defaultStage" job="defaultJob">
                <runif status="passed" />
              </fetchartifact>
              <exec command="tomcat.sh" workingdir="warTestDeploy/deployWar">
                <runif status="passed" />
              </exec>
            </tasks>
          </job>
        </jobs>
      </stage>
    </pipeline>
  </pipelines>
  <agents>
    <agent hostname="MYSGEC241372D" ipaddress="10.123.75.196" uuid="37628ff5-91f7-4c9a-a5f5-615e937f2650" />
  </agents>
</cruise>

我的控制台日志:

##|19:47:17.280 [go] Start to build test2/25/defaultStage/1/defaultJob on MYSGEC241372D [C:\Program Files\Go Agent]
!!|19:47:17.280 [go] Task: fetch artifact [deployWar] => [warTestDeploy] from [test1/defaultStage/defaultJob]
&1|19:47:17.280 [go] Fetching artifact [deployWar] from [test1/13/defaultStage/1/defaultJob]
&1|19:47:26.211 [go] Saved artifact to [pipelines\test2\warTestDeploy] after verifying the integrity of its contents.
?0|19:47:26.211 [go] Task status: passed (8931 ms)
!!|19:47:26.211 [go] Task: tomcat.sh
?1|19:49:06.044 [go] Task status: failed (99833 ms) (exit code: -1073741819)
j1|19:49:06.122 [go] Current job status: failed
##|19:49:06.169 [go] Start to create properties test2/25/defaultStage/1/defaultJob on MYSGEC241372D [C:\Program Files\Go Agent]
ar|19:49:06.169 [go] Start to upload test2/25/defaultStage/1/defaultJob on MYSGEC241372D [C:\Program Files\Go Agent]
ex|19:49:06.274 [go] Job completed test2/25/defaultStage/1/defaultJob on MYSGEC241372D [C:\Program Files\Go Agent]

1 个答案:

答案 0 :(得分:0)

我想我明白了。有人可以肯定或反驳我。

  1. 在线程中的某个地方遇到了这个问题,gocd在执行外部shell或bat文件时会考虑返回代码。如果返回码为0,则认为执行成功,否则,则认为执行相应的bat或shell脚本失败。在我的情况下,它必须是非零的返回码,因为不同的脚本和库将不同的返回码视为成功还是失败。手动设置返回码可能是解决方案。

  2. echo“ hello”只是一个实验,当我添加有意义的代码(有关使服务器实例启动并运行)时,它将保持打开新的CMD窗口,直到我手动杀死服务器实例为止,这意味着控制永不返回转到gocd,因此会出现超时错误。

对此发表评论,就再也无法访问代码了。