Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add options to push container on unstable/failed builds #98

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,22 @@ public class DockerJobProperty extends hudson.model.JobProperty<AbstractProject<
public final boolean tagOnCompletion;
public final String additionalTag;
public final boolean pushOnSuccess;
public final boolean pushOnUnstable;
public final boolean pushOnFailure;
public final boolean cleanImages;

@DataBoundConstructor
public DockerJobProperty(
boolean tagOnCompletion,
String additionalTag,
boolean pushOnSuccess, boolean cleanImages)
boolean pushOnSuccess, boolean pushOnUnstable,
boolean pushOnFailure, boolean cleanImages)
{
this.tagOnCompletion = tagOnCompletion;
this.additionalTag = additionalTag;
this.pushOnSuccess = pushOnSuccess;
this.pushOnUnstable = pushOnUnstable;
this.pushOnFailure = pushOnFailure;
this.cleanImages = cleanImages;
}

Expand All @@ -48,6 +53,14 @@ public boolean isPushOnSuccess() {
return pushOnSuccess;
}

@Exported
public boolean isPushOnUnstable() { return pushOnUnstable; }

@Exported
public boolean isPushOnFailure() {
return pushOnFailure;
}

@Exported
public boolean isTagOnCompletion() {
return tagOnCompletion;
Expand Down Expand Up @@ -75,6 +88,8 @@ public DockerJobProperty newInstance(StaplerRequest sr, JSONObject formData) thr
(Boolean)formData.get("tagOnCompletion"),
(String)formData.get("additionalTag"),
(Boolean)formData.get("pushOnSuccess"),
(Boolean)formData.get("pushOnUnstable"),
(Boolean)formData.get("pushOnFailure"),
(Boolean)formData.get("cleanImages"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ protected void _terminate(TaskListener listener) throws IOException, Interrupted
private void slaveShutdown(TaskListener listener) throws DockerException, IOException {

// The slave has stopped. Should we commit / tag / push ?

if(!getJobProperty().tagOnCompletion) {
addJenkinsAction(null);
return;
Expand Down Expand Up @@ -156,7 +155,11 @@ private void slaveShutdown(TaskListener listener) throws DockerException, IOExce
client.tagImageCmd(tag_image,null,tagToken).exec();
addJenkinsAction(tagToken);

if( getJobProperty().pushOnSuccess ) {
Result result = theRun.getResult();
boolean push = (getJobProperty().pushOnSuccess && result.equals(Result.SUCCESS)) ||
(getJobProperty().pushOnFailure && result.equals(Result.FAILURE)) ||
(getJobProperty().pushOnUnstable && result.equals(Result.UNSTABLE));
if( push ) {
client.pushImageCmd(tagToken).exec();
}
}
Expand Down Expand Up @@ -231,7 +234,7 @@ private DockerJobProperty getJobProperty() {
// Don't care.
}
// Safe default
return new DockerJobProperty(false,null,false, true);
return new DockerJobProperty(false, null, false, false, false, true);
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<f:section title="Docker Container">
<f:entry title="${%Commit on successful build}" field="tagOnCompletion">
<f:entry title="${%Commit on completed build}" field="tagOnCompletion">
<f:checkbox default="false"/>
</f:entry>

Expand All @@ -14,6 +14,14 @@
<f:checkbox/>
</f:entry>

<f:entry title="${%Push on unstable build}" field="pushOnUnstable">
<f:checkbox/>
</f:entry>

<f:entry title="${%Push on failed build}" field="pushOnFailure">
<f:checkbox/>
</f:entry>

<f:entry title="${%Clean local images}" field="cleanImages">
<f:checkbox default="true"/>
</f:entry>
Expand Down