Jenkinsのジョブでmavenantrunプラグインを使用してTomcatを起動しようとしています。貨物は同じように使えますが、使えません。理由は、ビルドが終了した後にアプリケーションを実行するTomcatが必要なためです。
これがシナリオです-私はプロジェクトをチェックアウトするジョブ1を持っています->それを構築します->それをTomcatにデプロイします。別のジョブは、ジョブ2が別のプロジェクトをチェックアウトし、それをESBにビルドしてデプロイし、ジョブ1にデプロイされたTomcatを使用して統合テストを実行すると言います。クリーンフェーズ-コンパイルフェーズの後にmavenantrunを使用して開始することを計画しています。次に、パッケージフェーズの後に再び貨物を使用して新しい戦争を再展開します。これを行う必要があるのは、Tomcatがテストビルドごとに更新され、Permgenなどの影響を受けないようにするためです。
とにかく問題は、次のスクリプトがコマンドプロンプトから正常に実行されることです。つまり、Tomcatが正常に起動し、Startup.batのコマンドウィンドウが開きます。しかし、Jenkinsで同じことを試してみると、実行されておらず、面白くて文句を言わないのです。単純な場合、Tomcatは起動しません。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>startTomcat</id>
<phase>compile</phase>
<configuration>
<target>
<exec executable="C:\Windows\System32\cmd.exe" spawn="true">
<arg value="/c" />
<arg value="D:\apache-tomcat-6.0.36\bin\startup.bat" />
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
これは私がジェンキンスで見るログです
[INFO] Executing tasks
Build sequence for target(s) `main' is [main]
Complete build sequence is [main, ]
main:
[exec] Current OS is Windows 7
[exec] Executing 'C:\Windows\System32\cmd.exe' with arguments:
[exec] '/c'
[exec] 'D:\apache-tomcat-6.0.36\bin\startup.bat'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
Execute:Java13CommandLauncher: Executing 'C:\Windows\System32\cmd.exe' with arguments:
'/c'
'D:\apache-tomcat-6.0.36\bin\startup.bat'
The ' characters around the executable and arguments are
not part of the command.
spawned process java.lang.ProcessImpl@ed11c1
[INFO] Executed tasks
mojoSucceeded org.apache.maven.plugins:maven-antrun-plugin:1.7(startTomcat)
私はexecutable="C:\ Windows \ System32\cmd.exe"とexecutable="cmd.exe"の両方を試しました-同じ問題、つまりコマンドプロンプトから実行すると正常に動作しますが、jenkinsではtomcatとどちらもエラーになりません。
Jenkinsをチェックしました-システム構成とuser.nameはNEW-LT7-0064$です。それが何らかの形で役立つかどうかはわかりませんが、コマンドプロンプトから実行すると、ユーザーはWindowsにログインしているユーザーです。また、ローカルシステムアカウントを使用してJenkinsをWindowsサービスとして実行しています。
私は次のことを試し、リンクhttps://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+buildで提案しました。 これはWindows64ビットWindows7マシンでも機能しませんでした。
Another workaraund for Windows XP and later is to shedule permanent task and force running it from the ant script.
Once run the command:
C:\>SCHTASKS /Create /RU SYSTEM /SC ONSTART /TN Tomcat /TR "C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin\startup.bat"
Note, that ONSTART can be replaced with ONCE if you do not want to keep Tomcat running.
Add the following code to your ant script:
<exec executable="SCHTASKS">
<arg value="/Run"/>
<arg value="/TN"/>
<arg value="Tomcat"/>
</exec>