5
votes

We have a Jenkins Maven build running on a Windows slave which runs maven package on every commit. I'm trying to use the promoted build plugin to deploy promoted builds to a nexus release repository.

I've set the "promote build when..." to manual approval and the action to "Deploy artifact to Maven Repository" set the repository URL to "http://example.com:8081/nexus/content/repositories/releases/" and the repo id to "release". However when the approval is triggered we get the following stack trace:

[INFO] Deployment in http://example.com:8081/nexus/content/repositories/releases/ (id=release,uniqueVersion=true) Deploying the main artifact artifactid-1.0.2.pom Uploading: http://example.com:8081/nexus/content/repositories/releases/groupid/artifactid/1.0.2/artifactid-1.0.2.pom ERROR: Failed to deploy artifacts: Could not transfer artifact groupid:artifactid:pom:1.0.2 from/to release (http://example.com:8081/nexus/content/repositories/releases/): Failed to transfer file: http://example.com:8081/nexus/content/repositories/releases/groupid/artifactid/1.0.2/artifactid-1.0.2.pom. Return code is: 401, ReasonPhrase: Unauthorized. org.apache.maven.artifact.deployer.ArtifactDeploymentException: Failed to deploy artifacts: Could not transfer artifact groupid:artifactid:pom:1.0.2 from/to release (http://example.com:8081/nexus/content/repositories/releases/): Failed to transfer file: http://example.com:8081/nexus/content/repositories/releases/groupid/artifactid/1.0.2/artifactid-1.0.2.pom. Return code is: 401, ReasonPhrase: Unauthorized. at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:143) at hudson.maven.reporters.MavenArtifactRecord.deploy(MavenArtifactRecord.java:193) at hudson.maven.RedeployPublisher.perform(RedeployPublisher.java:176) at hudson.plugins.promoted_builds.Promotion$RunnerImpl.build(Promotion.java:282) at hudson.plugins.promoted_builds.Promotion$RunnerImpl.doRun(Promotion.java:224) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:533) at hudson.model.Run.execute(Run.java:1740) at hudson.model.Run.run(Run.java:1678) at hudson.plugins.promoted_builds.Promotion.run(Promotion.java:174) at hudson.model.ResourceController.execute(ResourceController.java:89) at hudson.model.Executor.run(Executor.java:240)

If I change the promotion action to trigger maven deploy the build is re-run and the deploy target works as expected, if I add a git publisher this also fails on authentication. Both operations succeed if carried out locally by the user running Jenkins.

How does the promoted builds plugin determine the authentication details for deploy?

1
I have the same problem :( how to you deploy to a repository that requires authentication?Michael Wiles

1 Answers

0
votes

To perform a deploy that requires authentication with Maven, you need to configure a server with the proper information inside the settings.xml file. As such, modify (or create) your user settings (under ${user.home}/.m2/settings.xml) with the following:

<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>releases</id>
      <username>my_login</username>
      <password>my_password</password>
    </server>
  </servers>
  ...
</settings>

This defines a server configuration named releases with the given username and password. If needs be, you can use a passphrase or a private key instead.

Then, you need to make sure that Jenkins is correctly reading your Maven settings file. Under Jenkins 2.8, you can navigate to "Jenkins > Global Tool Configuration".

enter image description here

Those two options points to the global Maven settings and the user settings, that was modified earlier.

Finally, you need to make sure that the configured build action inside Jenkins is looking up the configured server. In your "Deploy artifacts to Maven repository" action, write your deploy URL and the "Repository ID" should be the <id> of the server configured in the settings.xml, which is releases in this case:

enter image description here