1

My scenario: I have deployed certain test files onto a server and I want to run a shell script on that remote server using maven. There is no maven plugin for the curent language hence I am doing it this way. The shell script will run the tests and generate an output in a .txt format.

My Problem: I have successfully ran the script using the maven-ant-run plugin BUT it does not show the maven output. After it executes the script, the output when running maven does not show anything after it. So in this case, using maven-ant-run is not ideal. This is part of my POM.xml:

<plugin>
            <!-- Step to copy the unit tests to designated destination -->
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <id>Deploy Unit tests onto Server</id>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <target>
                            <!-- Copy files to the remote integration test server -->
                            <!-- Transferring unit tests -->
                            <scp failonerror="true" todir="${scp.user}:${scp.password}@${scp.host}:/${scp.dirCopyToUnit}" trust="true">
                                <fileset dir="${scp.UnitTest.api.dir}">
                                    <include name="*"></include>
                                </fileset>
                            </scp>
                            <!-- transferring resources files -->
                            <scp failonerror="true" todir="${scp.user}:${scp.password}@${scp.host}:/${scp.dirCopyToUnitResources}" trust="true">
                                <fileset dir="${scp.UnitTest.api.dirResources}">
                                    <include name="*"></include>
                                </fileset>
                            </scp>
                            <!-- transferring spec_helper.lua -->
                            <scp failonerror="true" todir="${scp.user}:${scp.password}@${scp.host}:/${scp.dirCopySpec_Helpers}" trust="true">
                                <fileset dir="${scp.UnitTest.api.dirSpec_Helpers}">
                                    <include name="*"></include>
                                </fileset>
                            </scp>
                            <sshexec command="sh /tmp/unitTestMaven.sh exit exit" host="${scp.host}" password="${scp.password}" trust="yes" username="${scp.user}"></sshexec>
                            <taskdef classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec" classpathref="maven.plugin.classpath" name="sshexec"></taskdef>
                        </target>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.jcraft</groupId>
                    <artifactId>jsch</artifactId>
                    <version>0.1.53</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.ant</groupId>
                    <artifactId>ant-jsch</artifactId>
                    <version>1.8.4</version>
                </dependency>
            </dependencies>
        </plugin>

Can someone shed some light on this?

Possible resources: maven antrun ssh or scp hides the output

I've also tried using the wagon plugin:

 <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>wagon-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
                <execution>
                    <id>execute-test-commands</id>
                    <phase>test</phase>
                    <goals>
                        <goal>sshexec</goal>
                    </goals>
                    <configuration>
                        <serverId>atlassian-public</serverId>
                        <url>"scp://${scp.user}:${scp.password}@${scp.host}"</url>
                        <commands>
                            <command>sh /tmp/unitTestMaven.sh</command>
                        </commands>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

But getting the following error: org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:wagon-maven-plugin:1.0:sshexec (execute-test-commands) on project aa: Unable to create a Wagon instance

Community
  • 1
  • 1
lualover2017
  • 207
  • 1
  • 6
  • 16
  • Looks like you are trying to have some centralized "test" server, how about using jenkins? Also you should post the output you get with `mvn -X` –  Feb 09 '17 at 17:19
  • When running mvn -X, it also pauses after executing the script – lualover2017 Feb 09 '17 at 17:23
  • post the output Also did you try to wait, I mean maybe the script is taking some time to run? –  Feb 09 '17 at 17:25
  • The build does run but it doesn't show anything. Maven doesn't print out on the screen after running the script. I know it runs because there are files that are being transferred as part of the maven build. Maven -X still pauses after running the script – lualover2017 Feb 09 '17 at 17:34
  • I understand that, but do the `/tmp/unitTestMaven.sh` script finish and if yes, how do you know. You could also try using `verbose="yes"` on the `sshexec` –  Feb 09 '17 at 17:41
  • I know the script finishes because after the build phase where the script runs, in the deploy lifecycle, I transfer files to the server using maven and those files do get transfered. I've tried verbose="yes" and still same issue – lualover2017 Feb 09 '17 at 17:45
  • Why did you not follow [my suggestion to use the Wagon Plugin](http://stackoverflow.com/questions/42135738/how-to-execute-a-shell-script-in-maven#comment71440271_42135738)? To upload, you have the [`upload`](http://www.mojohaus.org/wagon-maven-plugin/upload-mojo.html) goal. – Tunaki Feb 09 '17 at 18:09
  • @Tunaki I have tried that but getting an error: `Cannot find wagon which supports the requested protocol: "scp: java.util.NoSuchElementException` – lualover2017 Feb 09 '17 at 18:12
  • @Tunaki I'll update this post to include the wagon plugin config – lualover2017 Feb 09 '17 at 18:13
  • I'm guessing this is because you missed the `` part here http://www.mojohaus.org/wagon-maven-plugin/usage.html. – Tunaki Feb 09 '17 at 18:15
  • @Tunaki I included the `` tag just below the `build` tag and was generating that error – lualover2017 Feb 09 '17 at 18:21
  • The quotes around the URL are weird: try to change to `scp://${scp.user}:${scp.password}@${scp.host}`. Also, make sure that those variables are correctly resolved (you can try by hard-coding something to test). Also, are you absolutely sure this is the right URL, with a password in it?! This URL points to the server, and typically doesn't contain credentials information. The credentials are located in the Maven Settings, i.e. the `~/.m2/settings.xml` file, under a server called `atlassian-public` since that is what you used for ``. – Tunaki Feb 09 '17 at 18:25
  • @Tunaki I do have a settings.xml and that does contain my credentials to another server. I did try unquoting the the url and still same error. I did try deleting the `serverId` tag and still same error. But I am 1000% sure the credentials are right – lualover2017 Feb 09 '17 at 18:33
  • But are you sure the URL is right? Can you connect to it using another tool, like WinSCP? – Tunaki Feb 09 '17 at 18:38
  • @Tunaki thanks for the help. Turns out i misspelt something. Deleting the severId worked. Thanks!! – lualover2017 Feb 09 '17 at 21:59

0 Answers0