Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
aliyun-oss-uploader
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tools
aliyun-oss-uploader
Commits
1f8d95c0
Commit
1f8d95c0
authored
Feb 17, 2022
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parent
e3e3cc42
Pipeline
#698
failed with stages
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
58 deletions
+57
-58
pom.xml
pom.xml
+12
-12
src/main/java/org/inurl/jenkins/plugin/OSSPublisher.java
src/main/java/org/inurl/jenkins/plugin/OSSPublisher.java
+45
-46
No files found.
pom.xml
View file @
1f8d95c0
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<parent>
<parent>
<groupId>
org.jenkins-ci.plugins
</groupId>
<groupId>
org.jenkins-ci.plugins
</groupId>
<artifactId>
plugin
</artifactId>
<artifactId>
plugin
</artifactId>
<version>
3.4
</version>
<version>
4.33
</version>
<relativePath
/>
<relativePath
/>
</parent>
</parent>
<groupId>
io.jenkins.plugins
</groupId>
<groupId>
io.jenkins.plugins
</groupId>
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
<packaging>
hpi
</packaging>
<packaging>
hpi
</packaging>
<properties>
<properties>
<!-- Baseline Jenkins version you use to build the plugin. Users must have this version or newer to run. -->
<!-- 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>
<jenkins.version>
2.
334
</jenkins.version>
<java.level>
8
</java.level>
<java.level>
8
</java.level>
<!-- Other properties you may want to use:
<!-- 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.
~ 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.
...
@@ -34,53 +34,53 @@
...
@@ -34,53 +34,53 @@
<dependency>
<dependency>
<groupId>
org.jenkins-ci.plugins
</groupId>
<groupId>
org.jenkins-ci.plugins
</groupId>
<artifactId>
structs
</artifactId>
<artifactId>
structs
</artifactId>
<version>
1.
7
</version>
<version>
1.
24
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.aliyun.oss
</groupId>
<groupId>
com.aliyun.oss
</groupId>
<artifactId>
aliyun-sdk-oss
</artifactId>
<artifactId>
aliyun-sdk-oss
</artifactId>
<version>
2.8.3
</version>
<version>
3.14.0
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<artifactId>
workflow-step-api
</artifactId>
<artifactId>
workflow-step-api
</artifactId>
<version>
2.
12
</version>
<version>
2.
24
</version>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<artifactId>
workflow-cps
</artifactId>
<artifactId>
workflow-cps
</artifactId>
<version>
2.
39
</version>
<version>
2.
94.1
</version>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<artifactId>
workflow-job
</artifactId>
<artifactId>
workflow-job
</artifactId>
<version>
2.
11.
2
</version>
<version>
2.
4
2
</version>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<artifactId>
workflow-basic-steps
</artifactId>
<artifactId>
workflow-basic-steps
</artifactId>
<version>
2.
6
</version>
<version>
2.
24
</version>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<artifactId>
workflow-durable-task-step
</artifactId>
<artifactId>
workflow-durable-task-step
</artifactId>
<version>
2.
13
</version>
<version>
2.
39
</version>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<artifactId>
workflow-api
</artifactId>
<artifactId>
workflow-api
</artifactId>
<version>
2.
20
</version>
<version>
2.
47
</version>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<groupId>
org.jenkins-ci.plugins.workflow
</groupId>
<artifactId>
workflow-support
</artifactId>
<artifactId>
workflow-support
</artifactId>
<version>
2.14
</version>
<version>
3.8
</version>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
</dependencies>
</dependencies>
...
@@ -113,4 +113,4 @@
...
@@ -113,4 +113,4 @@
</pluginRepository>
</pluginRepository>
</pluginRepositories>
</pluginRepositories>
</project>
</project>
\ No newline at end of file
src/main/java/org/inurl/jenkins/plugin/OSSPublisher.java
View file @
1f8d95c0
package
org.inurl.jenkins.plugin
;
package
org.inurl.jenkins.plugin
;
import
java.io.IOException
;
import
com.aliyun.oss.OSS
;
import
java.io.InputStream
;
import
com.aliyun.oss.OSSClientBuilder
;
import
java.io.PrintStream
;
import
hudson.EnvVars
;
import
javax.annotation.Nonnull
;
import
com.aliyun.oss.OSSClient
;
import
hudson.Extension
;
import
hudson.Extension
;
import
hudson.FilePath
;
import
hudson.FilePath
;
import
hudson.Launcher
;
import
hudson.Launcher
;
import
hudson.EnvVars
;
import
hudson.model.AbstractProject
;
import
hudson.model.AbstractProject
;
import
hudson.model.Run
;
import
hudson.model.Run
;
import
hudson.model.TaskListener
;
import
hudson.model.TaskListener
;
import
hudson.tasks.BuildStepDescriptor
;
import
hudson.tasks.BuildStepDescriptor
;
import
hudson.tasks.BuildStepMonitor
;
import
hudson.tasks.BuildStepMonitor
;
import
hudson.tasks.Publisher
;
import
hudson.tasks.Publisher
;
import
hudson.tasks.Recorder
;
import
hudson.util.FormValidation
;
import
hudson.util.FormValidation
;
import
hudson.util.Secret
;
import
hudson.util.Secret
;
import
jenkins.tasks.SimpleBuildStep
;
import
jenkins.tasks.SimpleBuildStep
;
...
@@ -25,7 +21,13 @@ import org.jenkinsci.Symbol;
...
@@ -25,7 +21,13 @@ import org.jenkinsci.Symbol;
import
org.kohsuke.stapler.DataBoundConstructor
;
import
org.kohsuke.stapler.DataBoundConstructor
;
import
org.kohsuke.stapler.QueryParameter
;
import
org.kohsuke.stapler.QueryParameter
;
public
class
OSSPublisher
extends
Publisher
implements
SimpleBuildStep
{
import
javax.annotation.Nonnull
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.PrintStream
;
@SuppressWarnings
(
"unused"
)
public
class
OSSPublisher
extends
Recorder
implements
SimpleBuildStep
{
private
final
String
endpoint
;
private
final
String
endpoint
;
...
@@ -39,7 +41,19 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
...
@@ -39,7 +41,19 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
private
final
String
remotePath
;
private
final
String
remotePath
;
private
final
String
maxRetries
;
private
final
Integer
maxRetries
;
@DataBoundConstructor
public
OSSPublisher
(
String
endpoint
,
String
accessKeyId
,
String
accessKeySecret
,
String
bucketName
,
String
localPath
,
String
remotePath
,
Integer
maxRetries
)
{
this
.
endpoint
=
endpoint
;
this
.
accessKeyId
=
accessKeyId
;
this
.
accessKeySecret
=
Secret
.
fromString
(
accessKeySecret
);
this
.
bucketName
=
bucketName
;
this
.
localPath
=
localPath
;
this
.
remotePath
=
remotePath
;
this
.
maxRetries
=
maxRetries
;
}
public
String
getEndpoint
()
{
public
String
getEndpoint
()
{
return
endpoint
;
return
endpoint
;
...
@@ -66,19 +80,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
...
@@ -66,19 +80,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
}
}
public
int
getMaxRetries
()
{
public
int
getMaxRetries
()
{
return
StringUtils
.
isEmpty
(
maxRetries
)
?
3
:
Integer
.
parseInt
(
maxRetries
);
return
maxRetries
==
null
?
3
:
maxRetries
;
}
@DataBoundConstructor
public
OSSPublisher
(
String
endpoint
,
String
accessKeyId
,
String
accessKeySecret
,
String
bucketName
,
String
localPath
,
String
remotePath
,
String
maxRetries
)
{
this
.
endpoint
=
endpoint
;
this
.
accessKeyId
=
accessKeyId
;
this
.
accessKeySecret
=
Secret
.
fromString
(
accessKeySecret
);
this
.
bucketName
=
bucketName
;
this
.
localPath
=
localPath
;
this
.
remotePath
=
remotePath
;
this
.
maxRetries
=
maxRetries
;
}
}
@Override
@Override
...
@@ -87,14 +89,13 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
...
@@ -87,14 +89,13 @@ 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
EnvVars
envVars
,
@Nonnull
TaskListener
listener
)
throws
InterruptedException
,
IOException
{
@Nonnull
Launcher
launcher
,
@Nonnull
TaskListener
listener
)
throws
InterruptedException
,
IOException
{
PrintStream
logger
=
listener
.
getLogger
();
PrintStream
logger
=
listener
.
getLogger
();
EnvVars
envVars
=
run
.
getEnvironment
(
listener
);
OSS
client
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
.
getPlainText
());
OSSClient
client
=
new
OSSClient
(
endpoint
,
accessKeyId
,
accessKeySecret
.
getPlainText
());
String
local
=
localPath
.
substring
(
1
);
String
local
=
localPath
.
substring
(
1
);
String
[]
remotes
=
remotePath
.
split
(
","
);
String
[]
remotes
=
remotePath
.
split
(
","
);
for
(
String
remote
:
remotes
)
{
for
(
String
remote
:
remotes
)
{
remote
=
remote
.
substring
(
1
);
remote
=
remote
.
substring
(
1
);
...
@@ -113,11 +114,10 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
...
@@ -113,11 +114,10 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
logger
.
println
(
"upload file success"
);
logger
.
println
(
"upload file success"
);
}
}
}
}
}
}
private
void
upload
(
OSSClient
client
,
PrintStream
logger
,
String
base
,
FilePath
path
,
boolean
root
)
private
void
upload
(
OSS
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
);
...
@@ -127,8 +127,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
...
@@ -127,8 +127,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
uploadFile
(
client
,
logger
,
base
+
"/"
+
path
.
getName
(),
path
);
uploadFile
(
client
,
logger
,
base
+
"/"
+
path
.
getName
(),
path
);
}
}
private
void
uploadFile
(
OSSClient
client
,
PrintStream
logger
,
String
key
,
FilePath
path
)
private
void
uploadFile
(
OSS
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
;
...
@@ -149,8 +148,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
...
@@ -149,8 +148,7 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
throw
new
RuntimeException
(
"upload fail, more than the max of retries"
);
throw
new
RuntimeException
(
"upload fail, more than the max of retries"
);
}
}
private
void
uploadFile0
(
OSSClient
client
,
PrintStream
logger
,
String
key
,
FilePath
path
)
private
void
uploadFile0
(
OSS
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
);
...
@@ -198,6 +196,17 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
...
@@ -198,6 +196,17 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
return
checkBeginWithSlash
(
value
);
return
checkBeginWithSlash
(
value
);
}
}
@Override
public
boolean
isApplicable
(
Class
<?
extends
AbstractProject
>
jobType
)
{
return
true
;
}
@Nonnull
@Override
public
String
getDisplayName
()
{
return
Messages
.
OSSPublish_DisplayName
();
}
private
FormValidation
checkBeginWithSlash
(
String
value
)
{
private
FormValidation
checkBeginWithSlash
(
String
value
)
{
if
(!
value
.
startsWith
(
"/"
))
{
if
(!
value
.
startsWith
(
"/"
))
{
return
FormValidation
.
error
(
Messages
.
OSSPublish_MustBeginWithSlash
());
return
FormValidation
.
error
(
Messages
.
OSSPublish_MustBeginWithSlash
());
...
@@ -212,16 +221,6 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
...
@@ -212,16 +221,6 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
return
FormValidation
.
ok
();
return
FormValidation
.
ok
();
}
}
@Override
public
boolean
isApplicable
(
Class
<?
extends
AbstractProject
>
jobType
)
{
return
true
;
}
@Nonnull
@Override
public
String
getDisplayName
()
{
return
Messages
.
OSSPublish_DisplayName
();
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment