我尝试通过npm module
部署exec-maven-plugin
。我使用https://github.com/arkanjoms/nexus-npm中的nexus-npm
工具。
在pom中,我是这样执行的:
<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>
一切正常,但是当部署失败时,maven构建仍被标记为成功。我怎样才能告诉maven在部署不成功时构建应该失败?
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] ------------------------------------------------------------------------
为明确起见,我知道部署失败的原因,这不是我的问题。我只想知道当部署出错时如何将Maven构建标记为失败。
答案 0 :(得分:1)
arkanjoms/nexus-npm插件使用app/publish-snapshot.js
publishSnapshot: function (snapshotRepository) {
log.info('publish snapshot => ' + snapshotRepository);
shell.exec('npm publish --registry=' + snapshotRepository);
},
这意味着shelljs/shelljs
exec
命令不会检查其返回码。
应该是:
if (shell.exec('npm publish --registry=' + snapshotRepository).code !== 0) {
shell.echo('Error: npm publish snapshot failed');
shell.exit(1);
}
类似地,该发布快照步骤的调用不会在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();
}
},
按照当前插件的实现情况,当部署出错时,将maven构建标记为失败并不容易。