When deploying jenkins, a pop-up prompts that the deployment was unsuccessful

When deploying the application in the company's production environment, an error was reported

Deploying [/root/.jenkins/workspace/bqj-open/anne-web-api/target/anne-web-api.war]
ERROR: Build step failed with exception
org.codehaus.cargo.container.ContainerException: Failed to deploy [/root/.jenkins/workspace/bqj-open/anne-web-api/target/anne-web-api.war]
	at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:107)
	at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:185)
	at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:73)
	at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:116)
	at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:103)
	at hudson.FilePath.act(FilePath.java:997)
	at hudson.FilePath.act(FilePath.java:975)
	at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:103)
	at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:61)
	at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:735)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:676)
	at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.post2(MavenModuleSetBuild.java:1072)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:621)
	at hudson.model.Run.execute(Run.java:1760)
	at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:542)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:405)
Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: FAIL - Deployed application at context path / but context failed to start


The version deployed by the company's jenkins is 2.60.1, the deployment plug-in used is
Deploy to container Plugin, and the version is version 1.10.
Baidu looked at the reasons, and most of them said to replace the /ROOT of ContextPath with /, but unfortunately it was not my reason. I looked at the source code of the plug-in. The general idea is to deploy through the manager-script role of tomcat, but I can deploy through the tomcat interface, but I get an error when deploying through the war package, but it is too troublesome to debug jenkins remotely. And it is still an online environment, so I simply wrote a small tool class directly based on the plug-in source code to test whether the deployment was successful or not.


public class TestJenkinsCargoDeploy {


    public static final String CHAR_SET="utf8";
    public static void main(String[] args) throws IOException {

        String path="/";
        String version=null;
        String config=null;
        String war=null;
        boolean update=false;
        String tag=null;
        InputStream data = new FileInputStream(new File("C://jenkins.war"));

        StringBuilder buffer = new StringBuilder("/deploy");
        try{
            buffer.append("?path=").append(URLEncoder.encode(path,CHAR_SET));
            if (version != null) {
                buffer.append("&version=").append(URLEncoder.encode(version, CHAR_SET));
            }
            if (config != null) {
                buffer.append("&config=").append(URLEncoder.encode(config.toString(), CHAR_SET));
            }
            if (war != null) {
                buffer.append("&war=").append(URLEncoder.encode(war.toString(), CHAR_SET));
            }
            if (update) {
                buffer.append("&update=true");
            }
            if (tag != null) {
                buffer.append("&tag=").append(URLEncoder.encode(tag, CHAR_SET));
            }
        }catch(Exception ex){

        }

        invoke(buffer.toString(),data);



    }

    public static void  invoke(String path,InputStream data) throws IOException {
        String url="http://localhost:8080/manager/text";
        String userAgent="Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36";
        String username="tomcat";
        String password="s3cret";


        URL invokeURL = new URL(url + path);
        HttpURLConnection connection = (HttpURLConnection)invokeURL.openConnection();
        connection.setAllowUserInteraction(false);
        connection.setDoInput(true);
        connection.setUseCaches(false);
        if (data == null)
        {
            connection.setDoOutput(false);
            connection.setRequestMethod("GET");
        }
        else
        {
            connection.setDoOutput(true);
            connection.setRequestMethod("PUT");
            connection.setRequestProperty("Content-Type", "application/octet-stream");

            connection.setChunkedStreamingMode (0);
        }
        if (userAgent != null) {
            connection.setRequestProperty("User-Agent", userAgent);
        }
        if (username != null)
        {
            String authorization = toAuthorization(username, password);
            connection.setRequestProperty("Authorization", authorization);
        }
        connection.connect();
        if (data != null) {
            pipe(data, connection.getOutputStream());
        }
        String response=null;
        try
        {
            response = toString(connection.getInputStream(), "UTF-8");
        }
        catch (IOException e)
        {
            e.printStackTrace ();
        }
        if (!response.startsWith("OK -")) {
            System.out.println(response);
        }


    }



    private static String toAuthorization(String username, String password)
    {
        StringBuilder buffer = new StringBuilder();
        buffer.append(username).append(':');
        if (password != null) {
            buffer.append(password);
        }
        return "Basic " + new String(Base64.encodeBase64(buffer.toString().getBytes()));
    }


    private static void pipe(InputStream in, OutputStream out)
            throws IOException
    {
        BufferedOutputStream bufferedOut = new BufferedOutputStream(out);

        byte[] bytes = new byte['?'];
        int n;
        while ((n = in.read(bytes)) != -1) {
            bufferedOut.write(bytes, 0, n);
        }
        bufferedOut.flush();
        bufferedOut.close();
        in.close();
    }

    private static String toString(InputStream in, String charset)
            throws IOException
    {
        InputStreamReader reader = new InputStreamReader(in, charset);

        StringBuilder buffer = new StringBuilder();
        char[] chars = new char['?'];
        int n;
        while ((n = reader.read(chars, 0, chars.length)) != -1) {
            buffer.append(chars, 0, n);
        }
        return buffer.toString();
    }
}







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326382306&siteId=291194637