How to use GnuPG in Jenkins for publishing Artifacts to Sonatype Nexus

54 Views Asked by At

I want to send the Maven project to Sonatype Oss for publishing an artifact in Maven Central. Two important files to send the project are root_of_project/pom.xml and admin/.m2/settings.xml

In pom.xml Nexus tags:

<plugin>
        <groupId>org.sonatype.plugins</groupId>
        <artifactId>nexus-staging-maven-plugin</artifactId>
        <version>1.6.13</version>
        <extensions>true</extensions>
        <configuration>
            <serverId>ossrh</serverId>
            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
            <autoReleaseAfterClose>true</autoReleaseAfterClose>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>com.thoughtworks.xstream</groupId>
                <artifactId>xstream</artifactId>
                <version>1.4.15</version>               
            </dependency>
        </dependencies>
    </plugin>

In settings.xml tags for Nexus and GpG:

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
    <server>
      <id>ossrh</id>
      <username>Nexus_name</username>
      <password>Nexus_password</password>
    </server>
</servers>
<profiles>
    <profile>
      <id>ossrh</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <gpg.executable>gpg</gpg.executable>
        <gpg.passphrase>gpg_passphrase</gpg.passphrase>
      </properties>
    </profile>
</profiles>

When I run a command in the root directory of my project: mvn clean deploy after a few seconds GnuPG opens a popup window where I need to insert my GPG passphrase and click on the OK button. enter image description here

Publish the artefact to Sonatype Nexus is done.

the question is: How can I configure my project in Jenkins to publish the artifact to Nexus automatically without inserting GPG passphrase manually when Jenkins build runs?

0

There are 0 best solutions below