maven 构建成功,虽然 npm 部署有错误
Maven build is successful although npm deployment has an error
我尝试通过 exec-maven-plugin
部署 npm module
。我使用 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\_logs19-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构建标记为失败
arkanjoms/nexus-npm plugin uses app/publish-snapshot.js
publishSnapshot: function (snapshotRepository) {
log.info('publish snapshot => ' + snapshotRepository);
shell.exec('npm publish --registry=' + snapshotRepository);
},
这意味着 shelljs/shelljs
exec
命令不检查其 return 代码。
应该是:
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 构建标记为失败并不容易。
我尝试通过 exec-maven-plugin
部署 npm module
。我使用 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\_logs19-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构建标记为失败
arkanjoms/nexus-npm plugin uses app/publish-snapshot.js
publishSnapshot: function (snapshotRepository) {
log.info('publish snapshot => ' + snapshotRepository);
shell.exec('npm publish --registry=' + snapshotRepository);
},
这意味着 shelljs/shelljs
exec
命令不检查其 return 代码。
应该是:
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 构建标记为失败并不容易。