1
votes

We are trying to get the M2 Release Plugin to deploy released artifacts to our Artifactory server. The configuration in our pom.xml looks like this

....
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.3.2</version>
</plugin>
....
<distributionManagement>
    <repository>
        <id>artifactory</id>
        <url>http://example.com/artifactory/jenkins-release</url>
    </repository>
</distributionManagement>

Using the Config File Provide Plugin we specified a global settings.xml with the proper credentials

<settings>
    <servers>
        <server>
            <id>artifactory</id>
            <username>jenkins</username>
            <password>secret!</password>
        </server>
    </servers>
</settings>

If we now start a release build on Jenkins, Maven tells us that there it received an HTTP 401 from artifactory

[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project example-maven-plugin: Failed to deploy artifacts: Could not transfer artifact com.example.maven.plugins:example-maven-plugin:jar:0.0.9 from/to artifactory (http://example.com/artifactory/jenkins-release): Failed to transfer file: http://example.com/artifactory/jenkins-release/com/example/maven/plugins/example-maven-plugin/0.0.9/example-maven-plugin-0.0.9.jar. Return code is: 401, ReasonPhrase:Unauthorized. -> [Help 1]

In the server logs we see that a user "non_authenticated_user" is trying to do a HTTP PUT request to this URL.

Is there some configuration in Maven or Jenkins we are missing? The credentials are correct and if I use the settings.xml from Jenkins on my local machine everything works as expected.

1
It looks like Jenkins didn't pick up the settings file you provided. Not sure about why, and a bit of an unrelated topic, why don't you use Artifactory Jenkins plugin? It solves this issue completely and has release functionality built-in. - JBaruch
That is what we thought, maybe a bug in the plugin, but I wanted to make sure that we did not miss anything. We do use this plugin, but only for the automatic deployment of SNAPSHOT builds. We found the release management of this plugin lacking some features the Jenkins M2 Release Plugin has (e.g. separate credentials for writing to the SCM, differentiating between release builds/non-release buids, ...) - moxn
You can customize the logic of release completely by using the staging user plugin. Some examples are in our GitHub - JBaruch
Thanks, @JBaruch. We will have a look at it. - moxn

1 Answers

1
votes

There is a bug in the Maven release plugin prior to 2.2.2 that makes it ignore the settings file being passed to Maven by the Config File Provider. The solution is to specify a newer maven release plugin in your projects pom.xml, like this:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.4.2</version>
        </plugin>
    </plugins>
</build>