简体   繁体   中英

How to run a jar file from the teamcity custom plugin code

I am working on developing a plugin for teamcity . The requirement is to run a jar file from the code which does some custom operation. I tried with the below code, but its not working for me.Any ideas on how to run the jar, links to documentation or sample code will help me a lot to progress further

public class CustomBuildProcess extends BuildProcessAdapter
{

private static final String     jarDir = "\\plugins\\teamcity-custom-plugin-agent\\lib\\metrics-17.6.4.4.jar";

@Override
public void start()
{
buildStatus = startProcess();

}

private BuildFinishedStatus startProcess() throws IOException
{

final GeneralCommandLine cmd = new GeneralCommandLine();
cmd.setExePath("java -jar C:\\BuildAgent"+jarDir);

final ExecResult result = SimpleCommandLineProcessRunner.runCommand(cmd, new byte[0]);

}

The following code worked for me.

final Runtime rTime = Runtime.getRuntime();
         final Process process = rTime.exec("java -jar
         C:\\TeamCity\\BuildAgent\\plugins\\teamcity-cutom-plugin-agent\\lib\\metrics-17.6.4.4.jar");
         logger.progressMessage(new String(IOUtils.toByteArray(process.getInputStream())));
         PrintStream printStream = new PrintStream(process.getOutputStream());
         logger.progressMessage(new String(IOUtils.toByteArray(process.getErrorStream())));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM