Unverified Commit c1755b04 authored by raylax's avatar raylax Committed by GitHub

Merge pull request #3 from seanchan/master

add one local file(dir) with multiple remotes support
parents 0b2b14c4 bbbeddc9
...@@ -71,7 +71,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep { ...@@ -71,7 +71,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
@DataBoundConstructor @DataBoundConstructor
public OSSPublisher(String endpoint, String accessKeyId, String accessKeySecret, String bucketName, public OSSPublisher(String endpoint, String accessKeyId, String accessKeySecret, String bucketName,
String localPath, String remotePath, String maxRetries) { String localPath, String remotePath, String maxRetries) {
this.endpoint = endpoint; this.endpoint = endpoint;
this.accessKeyId = accessKeyId; this.accessKeyId = accessKeyId;
this.accessKeySecret = Secret.fromString(accessKeySecret); this.accessKeySecret = Secret.fromString(accessKeySecret);
...@@ -88,32 +88,36 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep { ...@@ -88,32 +88,36 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
@Override @Override
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher, public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher,
@Nonnull TaskListener listener) throws InterruptedException, IOException { @Nonnull TaskListener listener) throws InterruptedException, IOException {
PrintStream logger = listener.getLogger(); PrintStream logger = listener.getLogger();
EnvVars envVars = run.getEnvironment(listener); EnvVars envVars = run.getEnvironment(listener);
OSSClient client = new OSSClient(endpoint, accessKeyId, accessKeySecret.getPlainText()); OSSClient client = new OSSClient(endpoint, accessKeyId, accessKeySecret.getPlainText());
String local = localPath.substring(1); String local = localPath.substring(1);
String remote = remotePath.substring(1);
String expandLocal = envVars.expand(local); String[] remotes = remotePath.split(",");
String expandRemote = envVars.expand(remote); for (String remote : remotes) {
logger.println("expandLocalPath =>" + expandLocal); remote = remote.substring(1);
logger.println("expandRemotePath =>" + expandRemote); String expandLocal = envVars.expand(local);
FilePath p = new FilePath(workspace, expandLocal); String expandRemote = envVars.expand(remote);
if (p.isDirectory()) { logger.println("expandLocalPath =>" + expandLocal);
logger.println("upload dir => " + p); logger.println("expandRemotePath =>" + expandRemote);
upload(client, logger, expandRemote, p, true); FilePath p = new FilePath(workspace, expandLocal);
logger.println("upload dir success"); if (p.isDirectory()) {
} else { logger.println("upload dir => " + p);
logger.println("upload file => " + p); upload(client, logger, expandRemote, p, true);
uploadFile(client, logger, expandRemote, p); logger.println("upload dir success");
logger.println("upload file success"); } else {
logger.println("upload file => " + p);
uploadFile(client, logger, expandRemote, p);
logger.println("upload file success");
}
} }
} }
private void upload(OSSClient client, PrintStream logger, String base, FilePath path, boolean root) private void upload(OSSClient client, PrintStream logger, String base, FilePath path, boolean root)
throws InterruptedException, IOException { throws InterruptedException, IOException {
if (path.isDirectory()) { if (path.isDirectory()) {
for (FilePath f : path.list()) { for (FilePath f : path.list()) {
upload(client, logger, base + (root ? "" : ("/" + path.getName())), f, false); upload(client, logger, base + (root ? "" : ("/" + path.getName())), f, false);
...@@ -124,7 +128,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep { ...@@ -124,7 +128,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
} }
private void uploadFile(OSSClient client, PrintStream logger, String key, FilePath path) private void uploadFile(OSSClient client, PrintStream logger, String key, FilePath path)
throws InterruptedException, IOException { throws InterruptedException, IOException {
if (!path.exists()) { if (!path.exists()) {
logger.println("file [" + path.getRemote() + "] not exists, skipped"); logger.println("file [" + path.getRemote() + "] not exists, skipped");
return; return;
...@@ -146,7 +150,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep { ...@@ -146,7 +150,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
} }
private void uploadFile0(OSSClient client, PrintStream logger, String key, FilePath path) private void uploadFile0(OSSClient client, PrintStream logger, String key, FilePath path)
throws InterruptedException, IOException { throws InterruptedException, IOException {
String realKey = key; String realKey = key;
if (realKey.startsWith("/")) { if (realKey.startsWith("/")) {
realKey = realKey.substring(1); realKey = realKey.substring(1);
......
<div> <div>
Remote file or directory, must begin with `/` Remote file or directory, must begin with `/`,
one local with multiple remotes distination require,pass "," for each remote path
</div> </div>
\ No newline at end of file
<div> <div>
远程路径,必须以`/`开头 远程路径,必须以`/`开头
如果有本地单文件(目录),远程多文件(目录)需求,请使用","进行远程路径分隔.
</div> </div>
\ No newline at end of file
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