简体   繁体   中英

maven-jarsigner-plugin fails during Jenkins build but not on command line

Following environment given:

  • Windows Server 2012
  • Java 1.6
  • Maven project with configured (assembly or shade plugin) AND jarsigner:sign/verify plugin
  • Jenkins 1.518 running within Tomcat 7 (which runs with Java 1.7)
  • Tomcat running as Windows Service User

When building the maven project everything works fine and the assembly is built (with the assembly plugin as well as with the shade plugin) and finally the assembly is signed and verified with the maven-jarsigner-plugin.

BUT the same project configured in Jenkins fails during build when jarsigner is trying to sign the assembly. Log File says:

message : Failed to execute goal org.apache.maven.plugins:maven-jarsigner-plugin:1.2:sign (sign) on project ext.pdfgui: Execution of 'cmd.exe /X /C ""C:\Program Files\Java\jdk1.6.0_43\jre\..\bin\jarsigner.exe" -verbose -keystore src/main/resources/signjar.keystore -storepass '*****' -keypass '*****' "D:\server\jenkinsWorkingDir\jobs\<project name>\workspace\trunk\<module>\target\artifact-jar-with-dependencies.jar" <cert alias>"' failed - Errorcode (1)
cause : Execution of 'cmd.exe /X /C ""C:\Program Files\Java\jdk1.6.0_43\jre\..\bin\jarsigner.exe" -verbose -keystore src/main/resources/signjar.keystore -storepass '*****' -keypass '*****' "D:\server\jenkinsWorkingDir\jobs\<project name>\workspace\trunk\<module>\target\artifact-jar-with-dependencies.jar" <cert alias>"' failed - Errorcode (1)
Stack trace : 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-jarsigner-plugin:1.2:sign (sign) on project ext.pdfgui: Execution of 'cmd.exe /X /C ""C:\Program Files\Java\jdk1.6.0_43\jre\..\bin\jarsigner.exe" -verbose -keystore src/main/resources/signjar.keystore -storepass '*****' -keypass '*****' "D:\server\jenkinsWorkingDir\jobs\<project name>\workspace\trunk\<module>\target\artifact-jar-with-dependencies.jar" <cert alias>"' failed - Errorcode (1)

I translated log file above from German to English so it might differ because I dont know exactly the right wording.

Verbose log file says:

[INFO] jarsigner: attempt to rename D:\server\jenkinsWorkingDir\jobs\<project name>\workspace\trunk\<module>\target\<artifact>-jar-with-dependencies.jar to D:\server\jenkinsWorkingDir\jobs\<project name>\workspace\trunk\<module>\target\<artifact>-jar-with-dependencies.jar.orig failed

Looking for a solution brought me to this blog entry: http://www.iliachemodanov.ru/en/blog-en/14-tools/maven/44-maven-assembly-plugin-bug-en

Here the "maven-shade-plugin" was mentioned as a solution, so I give it a try. Reconfigured pom file but with the same effect. It seams that Windows or Tomcat or Jenkins keeps a file handle on the assembly and the jarsigner plugin is not able to rename it.

So my answer for a possible solution. Any other more sophisticated solutions appreciated.

And here is how I solved it currently: I moved the asssembly/shade plugin (it doesn't matter which you use, its in your favour) to a maven profile called "assembly" which is active by default.

Then I moved the jarsigner plugin also to another plugin called "jarsigner" and also active by default.

So nothing changes when project is build from command line.

Then I configured Jenkins in first building the project with assmebly plugin activated and jarsigner plugin deactivated by calling

-Passembly,!jarsigner

And configured a post build step just calling following goals and arguments

deploy -P!assembly,jarsigner -DskipTests

Skipping tests here for performance because they should already passed during "normal" build and need not to be executed twice.

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