1

I try to deploy a npm module via exec-maven-plugin. I use the nexus-npm tool from https://github.com/arkanjoms/nexus-npm.

In my pom I execute it like this:

<execution>
  <id>Deploy module via nexus-npm</id>
  <goals>
    <goal>exec</goal>
  </goals>
  <phase>deploy</phase>
  <configuration>
    <workingDirectory>${project.build.directory}/npm</workingDirectory>
    <executable>nexus-npm</executable>
    <arguments>
      <argument>deploy</argument>
    </arguments>
    <environmentVariables>
      <HOME>${project.build.directory}/npm</HOME>
    </environmentVariables>
  </configuration>
</execution>

Everything works fine, but when the deployment is failing the maven build is still marked as successful. How can I tell maven that the build should fail when the deployment is not successful?

npm ERR! publish Failed PUT 400
npm ERR! code E400
npm ERR! Repository is read only: npm-internal-snapshots : mypackage

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Apps\npm-cache\_logs\2019-06-12T11_02_39_129Z-debug.log
[default.js-info]: Rollback files.
[default.js-info]: Cleaning files.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:12 min (Wall Clock)
[INFO] Finished at: 2019-06-12T13:02:39+02:00
[INFO] Final Memory: 43M/396M
[INFO] ------------------------------------------------------------------------

To clearify I know why the deployment is failing, that is not my question. I only want to know how to mark the maven build as failure when the deployment has an error.

ochs.tobi
  • 3,214
  • 7
  • 31
  • 52

1 Answers1

1

The arkanjoms/nexus-npm plugin uses app/publish-snapshot.js

publishSnapshot: function (snapshotRepository) {
    log.info('publish snapshot => ' + snapshotRepository);
    shell.exec('npm publish --registry=' + snapshotRepository);
},

That means the shelljs/shelljs exec command does not check its return code.

It should be:

if (shell.exec('npm publish --registry=' + snapshotRepository).code !== 0) {
  shell.echo('Error: npm publish snapshot failed');
  shell.exit(1);
}

Similarly, the call of that publish snapshot step don't expect any error in app/commands.js

    deploy: function () {
        this.verify();
        this.backup();
        if (commander.release) {
            tag.createTag(this.appConfig, this.config.tag, this.message);
            release.publishRelease(this.appConfig.packageJson.distributionManagement.releaseRegistry);
            release.updatePkgVersion(this.appConfig, this.message);
            rollback.clean();
        } else {
            snapshot.addDateToVersion(this.appConfig);
            snapshot.publishSnapshot(this.appConfig.packageJson.distributionManagement.snapshotRegistry);
            rollback.rollback();
        }
    },

As the current plugin implementation stands, it won't be easy to mark the maven build as failure when the deployment has an error.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks, thats exactly the problem. I forked the project and tried this and it works like a charm – ochs.tobi Jun 13 '19 at 09:03
  • 1
    @ochs.tobi Well done! That could be a PR (pull request) to be done to the original project! – VonC Jun 13 '19 at 09:04