如果Jenkinsfile中的构建失败,有没有办法执行清理(或回滚)?
我想通知我们的Atlassian Stash实例构建失败(通过curl在正确的URL处执行).
基本上,当构建状态设置为失败时,它将是一个后续步骤.
我应该用try {} catch ()吗?如果是这样,我应该捕获哪种异常类型?
是否有任何内置变量可以访问当前正在执行的构建的文本?
我试过用类似的东西currentBuild.log,currentBuild.buildLog但没有运气.
我正在尝试使用Java 9 HttpClient.
HttpRequest的javadoc中的基本示例可以正常工作:
HttpResponse response = HttpRequest.create(new URI("http://stackoverflow.com/"))
.version(java.net.http.HttpClient.Version.HTTP_2)
.followRedirects(HttpClient.Redirect.ALWAYS)
.GET()
.response();
int statusCode = response.statusCode();
String responseBody = response.body(HttpResponse.asString());
System.out.println("statusCode = " + statusCode);
System.out.println("responseBody = " + responseBody);
Run Code Online (Sandbox Code Playgroud)
但是,在尝试使用时sendAsyncMulti,它不起作用.没有创建文件E:\foo,未达到printlnafter join,也没有异常,虽然我基本上是从HttpResponse.multiFileJavadoc复制了这个例子.我希望一些HTTP响应将保存在该目录中.我还试图删除HTTP2和followRedirects,谷歌等其他URL,但它没有改变任何东西.我究竟做错了什么?
CompletableFuture<Map<URI,Path>> cf =
HttpRequest.create(new URI("http://stackoverflow.com/"))
.version(java.net.http.HttpClient.Version.HTTP_2)
.followRedirects(HttpClient.Redirect.ALWAYS)
.GET()
.multiResponseAsync(HttpResponse.multiFile(Paths.get("E:\\foo")));
Map<URI,Path> results = cf.join();
System.out.println("after join");
Run Code Online (Sandbox Code Playgroud)
如果它是相关的,这是我使用的版本(JDK 9的最新版本):
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+126)
Java HotSpot(TM) Server VM (build 9-ea+126, mixed mode)
Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的消息签名到Amazon AWS(在JUnit测试中),但我遇到了一个问题.这是我正在使用的代码:
String secretAccessKey = "secret1234678901";
SecretKeySpec keySpec = new SecretKeySpec(secretAccessKey.getBytes(UTF-8), "HmacSHA256");
Mac mac = Mac.getInstance(this.MAC_ALGO);
mac.init(keySpec); // here it breaks
byte[] encoded = mac.doFinal(
request.toString().getBytes(this.CHARSET));
return Base64.encodeBase64URLSafeString(encoded);
Run Code Online (Sandbox Code Playgroud)
在标记为(mac.init(...))的行中抛出异常:
java.lang.ClassCastException: com.sun.crypto.provider.HmacSHA1 cannot be cast to javax.crypto.MacSpi
at javax.crypto.Mac.a(DashoA13*..)
at javax.crypto.Mac.init(DashoA13*..)
Run Code Online (Sandbox Code Playgroud)
你知道为什么会这样吗?我在网上看到的所有代码看起来几乎都是这样的,我也尝试过使用HmacSHA1,结果相同.
所以我想尝试http客户端
package com.company;
import jdk.incubator.http.HttpClient;
public class Main {
public static void main(String[] args) {
HttpClient client = HttpClient.newHttpClient();
}
}
Run Code Online (Sandbox Code Playgroud)
我的模块信息看起来像这样
module com.company {
requires jdk.incubator.httpclient;
}
Run Code Online (Sandbox Code Playgroud)
但我明白了 java.lang.NoClassDefFoundError: jdk/incubator/http/HttpClient
我真的不明白为什么.我的java版本是"build 9-ea + 169",我使用最新版本的IntelliJ idea(2017.1.3).我查看了这个答案,看起来我只需要将需求添加到文件中,但由于某种原因它不起作用.
我正在尝试自动从生产系统上的visualvm获取CPU采样器数据.但要做到这一点,我需要一种方法来自动化Xvfb中的任务.
我发现xdotool很适合这种自动化.现在我有以下脚本:
Xvfb $DISPLAY -pixdepths 32 -screen 0 1280x1024x24 >/dev/null 2>&1 & XPID=$!
echo "Before twm"
#twm -display $DISPLAY &
gnome-wm &
#$VISUALVM --openpid $PID_TO_OPEN &
echo "Before gimp"
gimp &
sleep 5
xdotool search "GNU.*" windowactivate windowfocus key alt+f n
sleep 3
DISPLAY=:0.0
xwd -display :9.0 -root | xwdtopnm | pnmtopng > out.png
qiv out.png
Run Code Online (Sandbox Code Playgroud)
它应该打开Xvfb,运行gimp,然后单击File-> New.当我在普通X中执行此操作时会这样做,但是当我在Xvfb中执行此脚本时,看起来它不会传递键盘事件.我用鼠标测试它,它是相同的,xdotool没有传递(或Xvfb不接受)来自鼠标的事件.
有没有人遇到过这个问题并知道解决方案?
我正在尝试使用将项目迁移到Java 12 --enable-preview。
我--enable-preview在编译器设置中添加了:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>12</release>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
并在argLine中添加了它,以确保surefire和failsafe:
<properties>
<argLine>--enable-preview</argLine>
</properties>
Run Code Online (Sandbox Code Playgroud)
并mvn clean verify得出以下结果:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project lombok-jdk10: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test failed: java.lang.UnsupportedClassVersionError: Preview features are not enabled for com/kirela/lombok/BarTest (class file version 56.65535). Try running with '--enable-preview' -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
我也尝试将argLine直接添加到surefire / failsafe配置中,但是结果是相同的。
我在这里想念什么?
我这是surefire / failsafe中的错误吗?
EDIT2:Surefire和故障安全配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<forkCount>2</forkCount>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId> …Run Code Online (Sandbox Code Playgroud) java maven maven-surefire-plugin maven-failsafe-plugin java-12
我正在尝试使用抛出异常的应用程序调试问题,即使我使用-XX:MaxJavaStackTraceDepth=16777216(或那里的任何其他值,如-1或2048),堆栈跟踪也会被切断。
它是这样切断的:
Caused by: java.lang.IllegalStateException: unexpected message type: DefaultLastHttpContent
at io.netty.handler.codec.http.HttpObjectEncoder.encode(HttpObjectEncoder.java:124)
at io.netty.handler.codec.http.HttpClientCodec$Encoder.encode(HttpClientCodec.java:167)
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:89)
... 89 more
Run Code Online (Sandbox Code Playgroud)
我想看到更多的堆栈跟踪元素而不是... 89 more如何实现?
这是在 Java 8 中使用 SLF4J + Logback 使用以下配置进行日志记录:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<root level="info">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
Run Code Online (Sandbox Code Playgroud) 我试图谷歌这个问题,但找不到:在我们期望返回0或1行时,应该使用Spring jdbcTemplate中的推荐方法.queryForObject()将在没有返回任何行时抛出异常.queryForList()将需要遍历列表,但这不是问题.但我很好奇是否有返回0或1行的首选/推荐方法.谢谢!
如果发生任何编译器警告,我希望我的构建中断,所以我启用了-Werror.稍后我决定使用Java 9 HttpClient,这是一个孵化模块.不幸的是,我现在得到以下编译器警告:
using incubating module(s): jdk.incubator.httpclient
Run Code Online (Sandbox Code Playgroud)
有没有办法在-Werror不打破构建的情况下同时使用孵化模块?理想情况下,我想完全抑制这个警告.
我正在使用Maven来构建我的项目,所以理想情况下答案应该提供一个示例,说明如何将孵化模块作为Maven项目的一部分进行编译.
java ×7
java-9 ×3
jenkinsfile ×2
maven ×2
automation ×1
cryptoapi ×1
cryptography ×1
groovy ×1
java-12 ×1
java-8 ×1
jdbc ×1
jdbctemplate ×1
jenkins ×1
junit ×1
logback ×1
powermock ×1
slf4j ×1
spring ×1
spring-jdbc ×1
x11 ×1