forked from jenkinsci/integrity-plugin
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'refs/remotes/jenkinsci/master'
- Loading branch information
Showing
7 changed files
with
306 additions
and
1 deletion.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
src/main/java/hudson/scm/IntegritySCMChkptNotifierStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package hudson.scm; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
|
||
import com.mks.api.Command; | ||
import com.mks.api.Option; | ||
import com.mks.api.response.APIException; | ||
|
||
import hudson.FilePath; | ||
import hudson.Launcher; | ||
import hudson.model.TaskListener; | ||
import hudson.model.Run; | ||
import hudson.tasks.BuildStepMonitor; | ||
import hudson.tasks.Notifier; | ||
import jenkins.tasks.SimpleBuildStep; | ||
|
||
@SuppressWarnings("unchecked") | ||
public class IntegritySCMChkptNotifierStep extends Notifier implements SimpleBuildStep | ||
{ | ||
private static final Logger LOGGER = Logger.getLogger("IntegritySCM"); | ||
private final IntegrityConfigurable ciSettings; | ||
private final String configPath; | ||
private final String checkpointLabel; | ||
private final String checkpointDesc; | ||
|
||
public IntegritySCMChkptNotifierStep(IntegrityConfigurable ciSettings, String configPath, String checkpointLabel, String checkpointDesc) | ||
{ | ||
this.ciSettings = ciSettings; | ||
this.configPath = configPath; | ||
this.checkpointLabel = checkpointLabel; | ||
this.checkpointDesc = checkpointDesc; | ||
} | ||
|
||
public BuildStepMonitor getRequiredMonitorService() | ||
{ | ||
return BuildStepMonitor.NONE; | ||
} | ||
|
||
public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException | ||
{ | ||
APISession api = APISession.create(ciSettings); | ||
if( null != api ) | ||
{ | ||
listener.getLogger().println("Preparing to execute si checkpoint for project " + configPath); | ||
try | ||
{ | ||
// Construct the checkpoint command | ||
Command siCheckpoint = new Command(Command.SI, "checkpoint"); | ||
// Set the project name | ||
siCheckpoint.addOption(new Option("project", configPath)); | ||
// Set the label and description if applicable | ||
if( null != checkpointLabel && checkpointLabel.length() > 0 ) | ||
{ | ||
// Set the label | ||
siCheckpoint.addOption(new Option("label", checkpointLabel)); | ||
} | ||
|
||
if( null != checkpointDesc && checkpointDesc.length() > 0 ) | ||
{ | ||
// Set the description | ||
siCheckpoint.addOption(new Option("description", checkpointDesc)); | ||
} | ||
|
||
api.runCommand(siCheckpoint); | ||
listener.getLogger().println("Successfully checkpointed project " + configPath); | ||
} | ||
catch (APIException aex) | ||
{ | ||
LOGGER.severe("API Exception caught..."); | ||
ExceptionHandler eh = new ExceptionHandler(aex); | ||
aex.printStackTrace(listener.fatalError(eh.getMessage())); | ||
LOGGER.severe(eh.getMessage()); | ||
LOGGER.fine(eh.getCommand() + " returned exit code " + eh.getExitCode()); | ||
} | ||
finally | ||
{ | ||
api.Terminate(); | ||
} | ||
} | ||
else | ||
{ | ||
listener.getLogger().println("Failed to establish connection with Integrity!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
|
||
package hudson.scm; | ||
|
||
import hudson.Extension; | ||
import hudson.FilePath; | ||
import hudson.Launcher; | ||
import hudson.model.TaskListener; | ||
import hudson.model.Run; | ||
import hudson.scm.IntegritySCM.DescriptorImpl; | ||
import hudson.util.ListBoxModel; | ||
import hudson.util.Secret; | ||
|
||
import java.util.logging.Logger; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousStepExecution; | ||
import org.jenkinsci.plugins.workflow.steps.StepContextParameter; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
import org.kohsuke.stapler.QueryParameter; | ||
|
||
|
||
public class IntegritySCMChkptStep extends AbstractStepImpl | ||
{ | ||
private static final Logger LOGGER = Logger.getLogger("IntegritySCM"); | ||
|
||
private String serverConfig; | ||
private String userName; | ||
private Secret password; | ||
private String configPath; | ||
private String checkpointLabel; | ||
private String checkpointDesc; | ||
private IntegrityConfigurable connectionSettings; | ||
|
||
public String getServerConfig() | ||
{ | ||
return this.serverConfig; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setUserName(String userName) | ||
{ | ||
this.userName = userName; | ||
} | ||
|
||
public String getUserName() | ||
{ | ||
return this.userName; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setPassword(String password) | ||
{ | ||
this.password = Secret.fromString(password); | ||
} | ||
|
||
/** | ||
* Returns the project specific encrypted password of the user connecting to the Integrity Server | ||
* @return | ||
*/ | ||
public String getPassword() | ||
{ | ||
return this.password.getEncryptedValue(); | ||
} | ||
|
||
@DataBoundSetter | ||
public void setConfigPath(String configPath) | ||
{ | ||
this.configPath = configPath; | ||
} | ||
|
||
public String getConfigPath() | ||
{ | ||
return this.configPath; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setCheckpointLabel(String checkpointLabel) | ||
{ | ||
this.checkpointLabel = checkpointLabel; | ||
} | ||
|
||
public String getCheckpointLabel() | ||
{ | ||
return this.checkpointLabel; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setCheckpointDesc(String checkpointDesc) | ||
{ | ||
this.checkpointDesc = checkpointDesc; | ||
} | ||
|
||
public String getCheckpointDesc() | ||
{ | ||
return this.checkpointDesc; | ||
} | ||
|
||
public IntegrityConfigurable getConnectionSettings() | ||
{ | ||
IntegrityConfigurable desSettings = DescriptorImpl.INTEGRITY_DESCRIPTOR.getConfiguration(serverConfig); | ||
this.connectionSettings = new IntegrityConfigurable("TEMP_ID", desSettings.getIpHostName(), desSettings.getIpPort(), | ||
desSettings.getHostName(), desSettings.getPort(), desSettings.getSecure(), | ||
null == userName ? desSettings.getUserName() : userName, | ||
null == password ? desSettings.getPasswordInPlainText() : password.getPlainText()); | ||
|
||
return this.connectionSettings; | ||
} | ||
|
||
@DataBoundConstructor | ||
public IntegritySCMChkptStep(String serverConfig) | ||
{ | ||
this.serverConfig = serverConfig; | ||
IntegrityConfigurable config = getConnectionSettings(); | ||
this.userName = config.getUserName(); | ||
this.password = Secret.fromString(config.getPassword()); | ||
this.configPath = ""; | ||
this.checkpointLabel = ""; | ||
this.checkpointDesc = ""; | ||
|
||
LOGGER.fine("IntegritySCMChkptStep() constructed!"); | ||
} | ||
|
||
@Extension(optional = true) | ||
public static final class IntegritySCMChkptDescriptorImpl extends AbstractStepDescriptorImpl | ||
{ | ||
|
||
public IntegritySCMChkptDescriptorImpl() | ||
{ | ||
super(IntegritySCMChkptStepExecution.class); | ||
|
||
LOGGER.fine("IntegritySCMChkptDescriptorImpl() invoked!"); | ||
} | ||
|
||
@Override | ||
public String getFunctionName() | ||
{ | ||
return "sicheckpoint"; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() | ||
{ | ||
return "Integrity SCM Checkpoint"; | ||
} | ||
|
||
/** | ||
* Provides a list box for users to choose from a list of Integrity Server configurations | ||
* @param configuration Simple configuration name | ||
* @return | ||
*/ | ||
public ListBoxModel doFillServerConfigItems(@QueryParameter String serverConfig) | ||
{ | ||
return DescriptorImpl.INTEGRITY_DESCRIPTOR.doFillServerConfigItems(serverConfig); | ||
} | ||
} | ||
|
||
public static class IntegritySCMChkptStepExecution extends AbstractSynchronousStepExecution<Void> | ||
{ | ||
private static final long serialVersionUID = 7564942554899422192L; | ||
@Inject | ||
private transient IntegritySCMChkptStep step; | ||
@StepContextParameter | ||
private transient Run<?, ?> run; | ||
@StepContextParameter | ||
private transient FilePath workspace; | ||
@StepContextParameter | ||
private transient TaskListener listener; | ||
@StepContextParameter | ||
private transient Launcher launcher; | ||
|
||
@Override | ||
protected Void run() throws Exception | ||
{ | ||
IntegritySCMChkptNotifierStep notifier = new IntegritySCMChkptNotifierStep(step.getConnectionSettings(), step.getConfigPath(), step.getCheckpointLabel(), step.getCheckpointDesc()); | ||
notifier.perform(run, workspace, launcher, listener); | ||
return null; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/resources/hudson/scm/IntegritySCMChkptStep/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<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:entry title="Server Configuration ${hudson.utils.Util.filter(scmsteps,hudson.scm.IntegritySCMStep.class)}" field="serverConfig" help="/plugin/integrity-plugin/help-serverConfig.html"> | ||
<f:select /> | ||
</f:entry> | ||
|
||
<f:entry title="Integrity Project" field="configPath" help="/plugin/integrity-plugin/help-configPath.html"> | ||
<f:textbox clazz="required" checkMessage="'Integrity Project' is a required field!" /> | ||
</f:entry> | ||
|
||
<f:entry title="Project Specific Username" field="userName" help="/plugin/integrity-plugin/help-userName.html"> | ||
<f:textbox /> | ||
</f:entry> | ||
|
||
<f:entry title="Project Specific Password" field="password" help="/plugin/integrity-plugin/help-password.html"> | ||
<f:password /> | ||
</f:entry> | ||
|
||
<f:entry title="Checkpoint Label" field="checkpointLabel"> | ||
<f:textbox /> | ||
</f:entry> | ||
|
||
<f:entry title="Checkpoint Description" field="checkpointDesc" help="/plugin/integrity-plugin/help-checkpointDesc.html"> | ||
<f:textbox /> | ||
</f:entry> | ||
|
||
</j:jelly> |
3 changes: 3 additions & 0 deletions
3
src/main/resources/hudson/scm/IntegritySCMChkptStep/help-checkpointLabel.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
A valid Integrity Checkpoint label string. No groovy pre-processing is applied. | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/resources/hudson/scm/IntegritySCMLabelStep/help-checkpointLabel.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
A valid Integrity Checkpoint label string. No groovy pre-processing is applied. | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
Integrity Checkpoint description string | ||
</div> |