Jenkins Configuration for maven-gpg-plugin

50 Views Asked by At

I'm new to Jenkins, and I'm trying to create my first pipeline:

pipeline {
    
    agent any

    tools {
        maven "MAVEN_HOME"
    }

    stages {
        
        stage('Checkout') {
            steps {
                // GitHub repository
                git branch: 'release', url: 'https://github.com/paulmarcelinbejan/ToolBox.git'
            }
        }

        stage('Build') {
            steps {
                sh "mvn clean install" // <- not working
                //sh "mvn clean install -Dgpg.skip" // <- working
            }
        }
        
    }
    
    post {
        
        failure{
            emailext body: 'This email is to inform you about a failure.', subject: 'ToolBox Failure', to: '[email protected]'
        }
        
    }
}

I have copied my local settings.xml into "Dashboard > Manage Jenkins > Managed files":

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>ossrh</id>
      <username>paulmarcelinbejan</username>
      <password>MyRealSecretPassword</password>
    </server>
  </servers>
  <profiles>
    <profile>
      <id>ossrh</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <gpg.executable>gpg</gpg.executable>
        <gpg.passphrase>MyRealSecretPassphrase</gpg.passphrase>
      </properties>
    </profile>
  </profiles>
  <localRepository>~/.m2/repository</localRepository>
  <interactiveMode>true</interactiveMode>
  <offline>false</offline>
</settings>

when I start the build, I have this BUILD FAILURE:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.084 s
[INFO] Finished at: 2023-12-10T13:35:42Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:3.1.0:sign (sign-artifacts) on project toolbox: Exit code: 2 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

I have then installed 2 plugins: GPG signing with Software Trust Manager and rpmsign-plugin

and then on "Dashboard > Manage Jenkins > System" I have found a new section called :

RPM Signing Keys

where I have added the GPG key:
SecretKey: the one listed by the "gpg --list-keys" command.
Passphrase: the one written on settings.xml

pom.xml plusgins:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>${maven-gpg-plugin.version}</version>
            <executions>
                <execution>
                    <id>sign-artifacts</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>sign</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.sonatype.plugins</groupId>
            <artifactId>nexus-staging-maven-plugin</artifactId>
            <version>${nexus-staging-maven-plugin.version}</version>
            <extensions>true</extensions>
            <configuration>
                <serverId>ossrh</serverId>
                <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
                <autoReleaseAfterClose>true</autoReleaseAfterClose>
            </configuration>
        </plugin>

I think I have missed some config...

0

There are 0 best solutions below