Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from recena/JENKINS-28689
[JENKINS-28689] Make compatible with Workflow plugin
- Loading branch information
Showing
13 changed files
with
907 additions
and
24 deletions.
There are no files selected for viewing
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
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
99 changes: 99 additions & 0 deletions
99
src/main/java/com/cloudbees/jenkins/plugins/sshagent/SSHAgentStep.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,99 @@ | ||
package com.cloudbees.jenkins.plugins.sshagent; | ||
|
||
import com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey; | ||
import com.cloudbees.plugins.credentials.CredentialsProvider; | ||
import com.cloudbees.plugins.credentials.common.StandardUsernameListBoxModel; | ||
import com.cloudbees.plugins.credentials.domains.DomainRequirement; | ||
import hudson.Extension; | ||
import hudson.model.Item; | ||
import hudson.security.ACL; | ||
import hudson.util.ListBoxModel; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
import org.kohsuke.stapler.Stapler; | ||
|
||
import java.io.Serializable; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class SSHAgentStep extends AbstractStepImpl implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* The {@link com.cloudbees.plugins.credentials.common.StandardUsernameCredentials#getId()}s of the credentials | ||
* to use. | ||
*/ | ||
private final List<String> credentials; | ||
|
||
/** | ||
* If a credentials is missed, the SSH Agent is launched anyway. | ||
* By the fault is false. Initialized in the constructor. | ||
*/ | ||
private boolean ignoreMissing; | ||
|
||
/** | ||
* Default parameterized constructor. | ||
* | ||
* @param credentials | ||
*/ | ||
@DataBoundConstructor | ||
public SSHAgentStep(final List<String> credentials) { | ||
this.credentials = credentials; | ||
this.ignoreMissing = false; | ||
} | ||
|
||
@Extension | ||
public static final class DescriptorImpl extends AbstractStepDescriptorImpl { | ||
|
||
public DescriptorImpl() { | ||
super(SSHAgentStepExecution.class); | ||
} | ||
|
||
@Override | ||
public String getFunctionName() { | ||
return "sshagent"; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.SSHAgentBuildWrapper_DisplayName(); | ||
} | ||
|
||
@Override | ||
public boolean takesImplicitBlockArgument() { | ||
return true; | ||
} | ||
|
||
/** | ||
* Populate the list of credentials available to the job. | ||
* | ||
* @return the list box model. | ||
*/ | ||
@SuppressWarnings("unused") // used by stapler | ||
public ListBoxModel doFillCredentialsItems() { | ||
Item item = Stapler.getCurrentRequest().findAncestorObject(Item.class); | ||
return new StandardUsernameListBoxModel().withAll( | ||
CredentialsProvider.lookupCredentials(SSHUserPrivateKey.class, item, ACL.SYSTEM, | ||
Collections.<DomainRequirement>emptyList()) | ||
); | ||
} | ||
|
||
} | ||
|
||
@DataBoundSetter | ||
public void setIgnoreMissing(final boolean ignoreMissing) { | ||
this.ignoreMissing = ignoreMissing; | ||
} | ||
|
||
public boolean isIgnoreMissing() { | ||
return ignoreMissing; | ||
} | ||
|
||
public List<String> getCredentials() { | ||
return credentials; | ||
} | ||
|
||
} |
Oops, something went wrong.