Commit 36595791 authored by raylax's avatar raylax

fix issues

parent 07478cc6
......@@ -4,7 +4,7 @@
1.下载hpi文件
[aliyun-oss-plugin.hpi](https://github.com/raylax/jenkins-aliyun-oss-uploader/releases/latest)
[aliyun-oss-uploader.hpi](https://github.com/raylax/jenkins-aliyun-oss-uploader/releases/latest)
2.在plugins管理页面上传hpi文件并安装,重启jenkins
......
......@@ -14,7 +14,7 @@
<properties>
<!-- Baseline Jenkins version you use to build the plugin. Users must have this version or newer to run. -->
<jenkins.version>2.7.3</jenkins.version>
<java.level>7</java.level>
<java.level>8</java.level>
<!-- Other properties you may want to use:
~ jenkins-test-harness.version: Jenkins Test Harness version you use to test the plugin. For Jenkins version >= 1.580.1 use JTH 2.0 or higher.
~ hpi-plugin.version: The HPI Maven Plugin version used by the plugin..
......
......@@ -11,10 +11,10 @@ import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.util.FormValidation;
import hudson.util.Secret;
import jenkins.tasks.SimpleBuildStep;
import jnr.ffi.annotations.In;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
......@@ -30,7 +30,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
private final String accessKeyId;
private final String accessKeySecret;
private final Secret accessKeySecret;
private final String bucketName;
......@@ -50,7 +50,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
}
public String getAccessKeySecret() {
return accessKeySecret;
return accessKeySecret.getPlainText();
}
public String getBucketName() {
......@@ -73,7 +73,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
public OSSPublisher(String endpoint, String accessKeyId, String accessKeySecret, String bucketName, String localPath, String remotePath, String maxRetries) {
this.endpoint = endpoint;
this.accessKeyId = accessKeyId;
this.accessKeySecret = accessKeySecret;
this.accessKeySecret = Secret.fromString(accessKeySecret);
this.bucketName = bucketName;
this.localPath = localPath;
this.remotePath = remotePath;
......@@ -88,7 +88,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
@Override
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException {
PrintStream logger = listener.getLogger();
OSSClient client = new OSSClient(endpoint, accessKeyId, accessKeySecret);
OSSClient client = new OSSClient(endpoint, accessKeyId, accessKeySecret.getPlainText());
String local = localPath.substring(1);
String remote = remotePath.substring(1);
FilePath p = new FilePath(workspace, local);
......@@ -115,6 +115,10 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
}
private void uploadFile(OSSClient client, PrintStream logger, String key, FilePath path) throws InterruptedException, IOException {
if (!path.exists()) {
logger.println("file [" + path.getRemote() + "] not exists, skipped");
return;
}
int maxRetries = getMaxRetries();
int retries = 0;
do {
......@@ -143,6 +147,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
client.putObject(bucketName, realKey, inputStream);
}
@Symbol("aliyunOSSUpload")
@Extension
public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> {
......@@ -173,11 +178,18 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
}
public FormValidation doCheckLocalPath(@QueryParameter(required = true) String value) {
return checkValue(value, Messages.OSSPublish_MissingLocalPath());
return checkBeginWithSlash(value);
}
public FormValidation doCheckRemotePath(@QueryParameter(required = true) String value) {
return checkValue(value, Messages.OSSPublish_MissingRemotePath());
return checkBeginWithSlash(value);
}
private FormValidation checkBeginWithSlash(String value) {
if (!value.startsWith("/")) {
return FormValidation.error(Messages.OSSPublish_MustBeginWithSlash());
}
return FormValidation.ok();
}
private FormValidation checkValue(String value, String message) {
......
<?jelly escape-by-default='true'?>
<div>
TODO
</div>
......@@ -7,3 +7,4 @@ OSSPublish.MissingBucketName=Please set BucketName
OSSPublish.MissingLocalPath=Please set LocalPath
OSSPublish.MissingRemotePath=Please set RemotePath
OSSPublish.MaxRetiesMustBeNumbers=Must be number
OSSPublish.MustBeginWithSlash=Must begin with `/`
\ No newline at end of file
......@@ -7,3 +7,4 @@ OSSPublish.MissingBucketName=\u8bf7\u8bbe\u7f6eBucketName
OSSPublish.MissingLocalPath=\u8bf7\u8bbe\u7f6e\u672c\u5730\u8def\u5f84
OSSPublish.MissingRemotePath=\u8bf7\u8bbe\u7f6e\u8fdc\u7a0b\u8def\u5f84
OSSPublish.MaxRetiesMustBeNumbers=\u6700\u5927\u91cd\u8bd5\u6b21\u6570\u5fc5\u987b\u4e3a\u6570\u5b57
OSSPublish.MustBeginWithSlash=\u5fc5\u987b\u4ee5`/`\u5f00\u5934
\ No newline at end of file
<?jelly escape-by-default='true'?>
<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">
<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="${%Endpoint}" field="endpoint">
<f:textbox />
</f:entry>
......@@ -7,7 +11,7 @@
<f:textbox />
</f:entry>
<f:entry title="${%AccessKeySecret}" field="accessKeySecret">
<f:textbox />
<f:password/>
</f:entry>
<f:entry title="${%BucketName}" field="bucketName">
<f:textbox />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment