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 parameterless rebuild option for projects. #12

Merged
merged 2 commits into from
Sep 10, 2013
Merged
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
24 changes: 23 additions & 1 deletion src/main/java/com/sonyericsson/rebuild/RebuildAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,35 @@ public void doIndex(StaplerRequest request, StaplerResponse response) throws
if (currentBuild != null) {
ParametersAction paramAction = currentBuild.getAction(ParametersAction.class);
if (paramAction != null) {
response.sendRedirect(PARAMETERIZED_URL);
RebuildSettings settings = (RebuildSettings)getProject().getProperty(RebuildSettings.class);

if(settings != null && settings.getAuto_rebuild()) {
parameterizedRebuild(currentBuild, response);
} else {
response.sendRedirect(PARAMETERIZED_URL);
}
} else {
nonParameterizedRebuild(currentBuild, response);
}
}
}

public void parameterizedRebuild(AbstractBuild currentBuild, StaplerResponse response) throws IOException {
AbstractProject project = getProject();
if (project == null) {
return;
}
project.checkPermission(AbstractProject.BUILD);
if (isRebuildAvailable()) {

List<Action> actions = copyBuildCausesAndAddUserCause(currentBuild);
ParametersAction action = currentBuild.getAction(ParametersAction.class);
actions.add(action);

Hudson.getInstance().getQueue().schedule(build.getProject(), 0, actions);
response.sendRedirect("../../");
}
}
/**
* Call this method while rebuilding
* non parameterized build. .
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/com/sonyericsson/rebuild/RebuildSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* The MIT License
*
* Copyright 2013 gardnerj.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sonyericsson.rebuild;

import hudson.Extension;
import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

/**
*
* @author gardnerj
*/
public class RebuildSettings extends JobProperty<Job<?,?>> {

public boolean auto_rebuild;

@DataBoundConstructor
public RebuildSettings(boolean auto_rebuild) {
this.auto_rebuild = auto_rebuild;
}

public boolean getAuto_rebuild() {
return auto_rebuild;
}

@Extension
public final static class DescriptorImpl extends JobPropertyDescriptor {
@Override
public String getDisplayName() {
return "Rebuild Settings";
}

@Override
public boolean isApplicable(Class<? extends Job> jobType) {
return true;
}

@Override
public JobProperty<?> newInstance(StaplerRequest req, JSONObject formdata ) {
RebuildSettings prop = req.bindJSON(RebuildSettings.class, formdata);
return prop;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License

Copyright 2013 gardnerj.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<!-- TODO add taglibs such as: xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" -->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form" xmlns:d="jelly:define" xmlns:i="jelly:fmt">
<f:section title="Rebuild Settings">
<f:entry title="Automatically Rebuild Without Asking For Parameters" field="auto_rebuild">
<f:checkbox default="false" checked="${it.auto_rebuild}" />
</f:entry>
</f:section>
</j:jelly>