提交 51a53ab4 编写于 作者: J Jakub Štiller

JENKINS-12397: Skip deploying of artifacts when release build is running.

Monitor environment variable defined by user. If the variable is set to "true" the deployment is skipped. The M2 Release plugin expose this kind of variables.
上级 c20feab1
......@@ -92,30 +92,48 @@ public class RedeployPublisher extends Recorder {
public final String url;
public final boolean uniqueVersion;
public final boolean evenIfUnstable;
public final String releaseEnvVar;
/**
* For backward compatibility
*/
@Deprecated
public RedeployPublisher(String id, String url, boolean uniqueVersion) {
this(id, url, uniqueVersion, false);
this(id, url, uniqueVersion, false, null);
}
/**
* @since 1.347
*/
@DataBoundConstructor
@Deprecated
public RedeployPublisher(String id, String url, boolean uniqueVersion, boolean evenIfUnstable) {
this(id, url, uniqueVersion, evenIfUnstable, null);
}
@DataBoundConstructor
public RedeployPublisher(String id, String url, boolean uniqueVersion, boolean evenIfUnstable, String releaseEnvVar) {
this.id = id;
this.url = Util.fixEmptyAndTrim(url);
this.uniqueVersion = uniqueVersion;
this.evenIfUnstable = evenIfUnstable;
this.releaseEnvVar = Util.fixEmptyAndTrim(releaseEnvVar);
}
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
if (build.getResult().isWorseThan(getTreshold()))
return true; // build failed. Don't publish
/**
* Check if we should skip or not
*/
if (releaseEnvVar != null) {
String envVarValue = build.getEnvironment(listener).get(releaseEnvVar);
if ("true".equals(envVarValue)) { // null or false are ignored
listener.getLogger().println("[INFO] Skipping deploying artifact as release build is in progress.");
return true; // skip the deploy
}
}
List<MavenAbstractArtifactRecord> mavenAbstractArtifactRecords = getActions(build, listener);
if (mavenAbstractArtifactRecords == null || mavenAbstractArtifactRecords.isEmpty()) {
listener.getLogger().println("[ERROR] No artifacts are recorded. Is this a Maven project?");
......
......@@ -34,6 +34,9 @@ THE SOFTWARE.
<f:entry field="uniqueVersion">
<f:checkbox title="${%Assign unique versions to snapshots}" default="true"/>
</f:entry>
<f:entry title="${%Release environment variable}" field="releaseEnvVar" >
<f:textbox />
</f:entry>
<j:if test="${descriptor.showEvenIfUnstableOption()}">
<f:entry field="evenIfUnstable">
<f:checkbox title="${%Deploy even if the build is unstable}" />
......
<div>
If the given variable name is set to "true" the deploy steps is skipped. Useful when using m2 release plugin.
</div>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册