3

I configure my job as freestyle. And I need to run cases to a specified machine. MY project is maven project. I want to copy reports to master node after cases finish to run.

Jenkins ver. 1.483

I use pscp to copy files which works fine by hand in windows command prompt. My command looks like:

mvn clean install -U
pscp -P 22 -i pgrsa.ppk -r %SLAVE_JENKINS_HOME%\workspace\%JOB_NAME%\target\surefire-reports ci@master:%JENKINS_HOME%/workspace/%JOB_NAME%

The pscp seems not work. When I use command like this:

echo EchoCommand is working.===
mvn clean install -U
echo EchoCommand is working again.===

EchoCommand is working again.===Not show at the output of the console while EchoCommand is working.=== has been shown. Why? Anyone knows that?

EDIT

C:\Tools\Jenkins\workspace\myproject-testng-sample-windows>echo EchoCommand is working.=== 
EchoCommand is working.===

C:\Tools\Jenkins\workspace\myproject-testng-sample-windows>mvn clean install -U 
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.pak.automation:myproject-testng-sample:jar:1.0.0-SNPASHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-deploy-plugin is missing. @ com.pak:pak-parent:2.0.0, C:\Users\pak\.m2\repository\com\pak\pak-parent\2.0.0\pak-parent-2.0.0.pom, line 484, column 12
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-source-plugin is missing. @ com.pak:pak-parent:2.0.0, C:\Users\pak\.m2\repository\com\pak\pak-parent\2.0.0\pak-parent-2.0.0.pom, line 472, column 12
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject-testng-sample 1.0.0-SNPASHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://mvn.pak.com/pakrepo/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml
Downloading: http://mvn.pak.com/pak-releases/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml
Downloading: http://mvn.pak.com/pak-snapshots/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml
Downloading: http://mvn.pak.com/third-party/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml


377/377 B   
377/377 B   377/377 B   

Downloaded: http://mvn.pak.com/third-party/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml (377 B at 1.5 KB/sec)

Downloaded: http://mvn.pak.com/pakrepo/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml (377 B at 1.4 KB/sec)
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ myproject-testng-sample ---
[INFO] Deleting C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ myproject-testng-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) @ myproject-testng-sample ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.3:testResources (default-testResources) @ myproject-testng-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.0.2:testCompile (default-testCompile) @ myproject-testng-sample ---
[INFO] Compiling 4 source files to C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ myproject-testng-sample ---
[INFO] Surefire report directory: C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@4d20a47e
testMethod1
testMethod2
testMethodmyproject2
testmyprojectSample
testMethod1
testMethod2
testMethodmyproject2
testmyprojectSample
we wont run test with class name: com.pak.myproject.sample.NoInjectionTest
we wont run test with class name: com.pak.myproject.sample.NoInjectionTest
I am test method 2
parameter in test method is: firstname
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.895 sec

Results :

Tests run: 4, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ myproject-testng-sample ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target\myproject-testng-sample-1.0.0-SNPASHOT.jar
[INFO] 
[INFO] >>> maven-source-plugin:2.1.1:jar (attach-sources) @ myproject-testng-sample >>>
[INFO] 
[INFO] <<< maven-source-plugin:2.1.1:jar (attach-sources) @ myproject-testng-sample <<<
[INFO] 
[INFO] --- maven-source-plugin:2.1.1:jar (attach-sources) @ myproject-testng-sample ---
[INFO] No sources in project. Archive not created.
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ myproject-testng-sample ---
[INFO] Installing C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target\myproject-testng-sample-1.0.0-SNPASHOT.jar to C:\Users\pak\.m2\repository\com\pak\automation\myproject-testng-sample\1.0.0-SNPASHOT\myproject-testng-sample-1.0.0-SNPASHOT.jar
[INFO] Installing C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\pom.xml to C:\Users\pak\.m2\repository\com\pak\automation\myproject-testng-sample\1.0.0-SNPASHOT\myproject-testng-sample-1.0.0-SNPASHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.649 s
[INFO] Finished at: 2014-04-08T13:19:58+08:00
[INFO] Final Memory: 10M/24M
[INFO] ------------------------------------------------------------------------
Recording test results
TestNG Reports Processing: START
Nick Dong
  • 3,638
  • 8
  • 47
  • 84

4 Answers4

7

mvn is a batch file. So It is need to call mvn .... Not just mvn ....

See call-batch-file-from-cygwin-breaks-after-1st-command

Community
  • 1
  • 1
Nick Dong
  • 3,638
  • 8
  • 47
  • 84
1

This could be due to an environment problem. You could, however, save yourself a lot of time and work by doing things a little bit different:

  • Make your job a Maven Project, makes configuration easier (and offers you nice features like test reports for single modules etc.). This might also make your report copying unneccessary.

  • Depending on what you want to do with these reports afterwards, you could simple use the Jenkins archiving mechanism to copy them over to your master.

  • if you REALLY need to copy them by hand, use the Publish Over SSH Jenkinsn plugin

blackbuild
  • 5,026
  • 1
  • 23
  • 35
  • My partner configured the job as freestyle, since slave node is windows which is different with master node(linux). What do you mean `environment problem`? Windows problem? @blackbuild – Nick Dong Apr 04 '14 at 08:37
  • @NickDong Classical problem would be something like a missing PATH entry. From commandline, everything works, but from Jenkins it does not. I don't understand the reasoning for a freestyle job. Heterogenous environments is one of the major reasons for NOT using something like command line or shell. – blackbuild Apr 04 '14 at 08:50
  • Commands before 'mvn clean test -U' can be executed normally. It indicates that jenkins find commands in PATH, right? @blackbuild – Nick Dong Apr 04 '14 at 10:23
  • And I need to run cases to specified machines. – Nick Dong Apr 04 '14 at 10:24
  • @NickDong Yes. But why copy the results back to master? Jenkins already archives the test results, so why do it twice? This might not solve the actual problem, but get you a workable version. – blackbuild Apr 07 '14 at 07:48
  • Because qa-report of my job not shows correctly. @blackbuild Maybe copy the result files to master would be helpful, I think. – Nick Dong Apr 08 '14 at 08:11
  • Well, I know what happend about windows command prompt. `mvn` is a batch file. So It is need to `call mvn ...`. Not just `mvn ...`. – Nick Dong Apr 08 '14 at 08:13
  • [call-batch-file-from-cygwin-breaks-after-1st-command](http://stackoverflow.com/questions/4877099/call-batch-file-from-cygwin-breaks-after-1st-command) – Nick Dong Apr 08 '14 at 08:21
  • Good to see it works now. Please create an answer out of your link and accept it (to mark it as solved). You should still consider/try using a maven-job – blackbuild Apr 08 '14 at 08:25
  • A maven job seems not allowed to configure to use one machine(`Restrict where this project can be run`) to run the job. @blackbuild – Nick Dong Apr 08 '14 at 09:42
  • @NickDong This can only be a bug in your specific version. I make extensive use restrictions using maven projects and never encountered this problem (with various versions of jenkins, we update regularily) – blackbuild Apr 08 '14 at 09:54
  • What is your version? Mine is Jenkins ver. 1.483. @blackbuild – Nick Dong Apr 08 '14 at 09:57
  • @NickDong Right now 1.551, but the projects is running for three years so we went through a lot of version. – blackbuild Apr 08 '14 at 10:03
0

Are you using Execute Shell in your free-style project, i.e. you are running on a *nix based environment? If so, your problem is detailed in my answer here:
Jenkins Build Script exits after Google Test execution

Jenkins launches Execute Shell as a temporary shell script with command /bin/sh -xe tempshell.sh. Note the -e part. This tells sh to exit when any single command in the script returns with non-zero value.

Your mvn clean install -U is probably returning with a non-zero value. You can check that by running it on command line, immediately followed by echo $?

Solution: To circumvent that, add set +e to the top of your Execute Shell script.

Community
  • 1
  • 1
Slav
  • 27,057
  • 11
  • 80
  • 104
0

The problem may be that you are not giving enter after the last command.

Today I came across the same problem in our project, last command in jenkins is not executed.

After some trail and error methods, came to understand that.

Sivaprasad
  • 109
  • 1
  • 5