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
08f4e3fb
Commit
08f4e3fb
authored
Jun 05, 2019
by
raylax
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
4713f40d
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
106 deletions
+71
-106
pom.xml
pom.xml
+12
-7
src/main/java/org/inurl/jenkins/plugin/OSSPublisher.java
src/main/java/org/inurl/jenkins/plugin/OSSPublisher.java
+50
-19
src/main/resources/org/inurl/jenkins/plugin/Messages_zh.properties
...resources/org/inurl/jenkins/plugin/Messages_zh.properties
+2
-2
src/main/resources/org/inurl/jenkins/plugin/OSSPublisher/help-bucketName.html
...rg/inurl/jenkins/plugin/OSSPublisher/help-bucketName.html
+4
-0
src/main/resources/org/inurl/jenkins/plugin/OSSPublisher/help-remotePath.html
...rg/inurl/jenkins/plugin/OSSPublisher/help-remotePath.html
+3
-0
src/test/java/org/inurl/jenkins/plugin/HelloWorldBuilderTest.java
.../java/org/inurl/jenkins/plugin/HelloWorldBuilderTest.java
+0
-78
No files found.
pom.xml
View file @
08f4e3fb
...
@@ -21,8 +21,8 @@
...
@@ -21,8 +21,8 @@
~ stapler-plugin.version: The Stapler Maven plugin version required by the plugin.
~ stapler-plugin.version: The Stapler Maven plugin version required by the plugin.
-->
-->
</properties>
</properties>
<name>
TODO Plugin
</name>
<name>
Aliyun OSS Upload
</name>
<description>
TODO
</description>
<description>
Aliyun OSS Upload plugin
</description>
<!-- The default licence for Jenkins OSS Plugins is MIT. Substitute for the applicable one if needed. -->
<!-- The default licence for Jenkins OSS Plugins is MIT. Substitute for the applicable one if needed. -->
<licenses>
<licenses>
<license>
<license>
...
@@ -36,6 +36,11 @@
...
@@ -36,6 +36,11 @@
<artifactId>
structs
</artifactId>
<artifactId>
structs
</artifactId>
<version>
1.7
</version>
<version>
1.7
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.aliyun.oss
</groupId>
<artifactId>
aliyun-sdk-oss
</artifactId>
<version>
2.8.3
</version>
</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>
...
@@ -80,14 +85,13 @@
...
@@ -80,14 +85,13 @@
</dependency>
</dependency>
</dependencies>
</dependencies>
<!-- If you want this to appear on the wiki page:
<developers>
<developers>
<developer>
<developer>
<id>
bhacker
</id>
<id>
raylax
</id>
<name>
Bob Q. Hacker
</name>
<name>
YangchunYu
</name>
<email>
bhacker@nowhere.net
</email>
<email>
raylax@inurl.org
</email>
</developer>
</developer>
</developers>
-->
</developers>
<!-- Assuming you want to host on @jenkinsci:
<!-- Assuming you want to host on @jenkinsci:
<url>https://wiki.jenkins.io/display/JENKINS/TODO+Plugin</url>
<url>https://wiki.jenkins.io/display/JENKINS/TODO+Plugin</url>
...
@@ -109,4 +113,5 @@
...
@@ -109,4 +113,5 @@
<url>
https://repo.jenkins-ci.org/public/
</url>
<url>
https://repo.jenkins-ci.org/public/
</url>
</pluginRepository>
</pluginRepository>
</pluginRepositories>
</pluginRepositories>
</project>
</project>
src/main/java/org/inurl/jenkins/plugin/OSSPublisher.java
View file @
08f4e3fb
package
org.inurl.jenkins.plugin
;
package
org.inurl.jenkins.plugin
;
import
com.aliyun.oss.OSSClient
;
import
hudson.Extension
;
import
hudson.FilePath
;
import
hudson.FilePath
;
import
hudson.Launcher
;
import
hudson.Launcher
;
import
hudson.model.AbstractProject
;
import
hudson.model.Run
;
import
hudson.model.Run
;
import
hudson.model.TaskListener
;
import
hudson.model.TaskListener
;
import
hudson.util.FormValidation
;
import
jenkins.tasks.SimpleBuildStep
;
import
org.apache.commons.lang.StringUtils
;
import
org.inurl.jenkins.plugin.Messages
;
import
hudson.Extension
;
import
hudson.model.AbstractProject
;
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.util.FormValidation
;
import
jenkins.tasks.SimpleBuildStep
;
import
org.apache.commons.lang.StringUtils
;
import
org.kohsuke.stapler.DataBoundConstructor
;
import
org.kohsuke.stapler.DataBoundConstructor
;
import
org.kohsuke.stapler.QueryParameter
;
import
org.kohsuke.stapler.QueryParameter
;
import
javax.annotation.Nonnull
;
import
javax.annotation.Nonnull
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.PrintStream
;
public
class
OSSPublisher
extends
Publisher
implements
SimpleBuildStep
{
public
class
OSSPublisher
extends
Publisher
implements
SimpleBuildStep
{
...
@@ -76,39 +78,68 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
...
@@ -76,39 +78,68 @@ public class OSSPublisher extends Publisher implements SimpleBuildStep {
@Override
@Override
public
void
perform
(
@Nonnull
Run
<?,
?>
run
,
@Nonnull
FilePath
workspace
,
@Nonnull
Launcher
launcher
,
@Nonnull
TaskListener
listener
)
throws
InterruptedException
,
IOException
{
public
void
perform
(
@Nonnull
Run
<?,
?>
run
,
@Nonnull
FilePath
workspace
,
@Nonnull
Launcher
launcher
,
@Nonnull
TaskListener
listener
)
throws
InterruptedException
,
IOException
{
listener
.
getLogger
().
println
(
"endpoint => "
+
endpoint
+
"!"
);
PrintStream
logger
=
listener
.
getLogger
();
listener
.
getLogger
().
println
(
"accessKeyId => "
+
accessKeyId
+
"!"
);
OSSClient
client
=
new
OSSClient
(
endpoint
,
accessKeyId
,
accessKeySecret
);
listener
.
getLogger
().
println
(
"accessKeySecret => "
+
accessKeySecret
+
"!"
);
String
local
=
localPath
.
substring
(
1
);
listener
.
getLogger
().
println
(
"bucketName => "
+
bucketName
+
"!"
);
String
remote
=
remotePath
.
substring
(
1
);
listener
.
getLogger
().
println
(
"localPath => "
+
localPath
+
"!"
);
logger
.
println
(
"workspace => "
+
workspace
);
listener
.
getLogger
().
println
(
"remotePath => "
+
remotePath
+
"!"
);
FilePath
p
=
new
FilePath
(
workspace
,
local
);
if
(
p
.
isDirectory
())
{
logger
.
println
(
"upload dir => "
+
p
);
upload
(
client
,
logger
,
remote
,
p
,
true
);
}
else
{
logger
.
println
(
"upload file => "
+
p
);
uploadFile
(
client
,
logger
,
remote
,
p
);
}
}
private
void
upload
(
OSSClient
client
,
PrintStream
logger
,
String
base
,
FilePath
path
,
boolean
root
)
throws
InterruptedException
,
IOException
{
if
(
path
.
isDirectory
())
{
for
(
FilePath
f
:
path
.
list
())
{
upload
(
client
,
logger
,
base
+
(
root
?
""
:
(
"/"
+
path
.
getName
())),
f
,
false
);
}
return
;
}
uploadFile
(
client
,
logger
,
base
+
"/"
+
path
.
getName
(),
path
);
}
private
void
uploadFile
(
OSSClient
client
,
PrintStream
logger
,
String
key
,
FilePath
path
)
throws
InterruptedException
,
IOException
{
String
realKey
=
key
;
if
(
realKey
.
startsWith
(
"/"
))
{
realKey
=
realKey
.
substring
(
1
);
}
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
path
.
copyTo
(
outputStream
);
ByteArrayInputStream
inputStream
=
new
ByteArrayInputStream
(
outputStream
.
toByteArray
());
logger
.
println
(
"uploading ["
+
path
.
getRemote
()
+
"] to ["
+
realKey
+
"]"
);
client
.
putObject
(
bucketName
,
realKey
,
inputStream
);
}
}
@Extension
@Extension
public
static
final
class
DescriptorImpl
extends
BuildStepDescriptor
<
Publisher
>
{
public
static
final
class
DescriptorImpl
extends
BuildStepDescriptor
<
Publisher
>
{
public
FormValidation
doCheckEndpoint
(
@QueryParameter
String
value
)
{
public
FormValidation
doCheckEndpoint
(
@QueryParameter
(
required
=
true
)
String
value
)
{
return
checkValue
(
value
,
Messages
.
OSSPublish_MissingEndpoint
());
return
checkValue
(
value
,
Messages
.
OSSPublish_MissingEndpoint
());
}
}
public
FormValidation
doCheckAccessKeyId
(
@QueryParameter
String
value
)
{
public
FormValidation
doCheckAccessKeyId
(
@QueryParameter
(
required
=
true
)
String
value
)
{
return
checkValue
(
value
,
Messages
.
OSSPublish_MissingAccessKeyId
());
return
checkValue
(
value
,
Messages
.
OSSPublish_MissingAccessKeyId
());
}
}
public
FormValidation
doCheckAccessKeySecret
(
@QueryParameter
String
value
)
{
public
FormValidation
doCheckAccessKeySecret
(
@QueryParameter
(
required
=
true
)
String
value
)
{
return
checkValue
(
value
,
Messages
.
OSSPublish_MissingAccessKeySecret
());
return
checkValue
(
value
,
Messages
.
OSSPublish_MissingAccessKeySecret
());
}
}
public
FormValidation
doCheckBucketName
(
@QueryParameter
String
value
)
{
public
FormValidation
doCheckBucketName
(
@QueryParameter
(
required
=
true
)
String
value
)
{
return
checkValue
(
value
,
Messages
.
OSSPublish_MissingBucketName
());
return
checkValue
(
value
,
Messages
.
OSSPublish_MissingBucketName
());
}
}
public
FormValidation
doCheckLocalPath
(
@QueryParameter
String
value
)
{
public
FormValidation
doCheckLocalPath
(
@QueryParameter
(
required
=
true
)
String
value
)
{
return
checkValue
(
value
,
Messages
.
OSSPublish_MissingLocalPath
());
return
checkValue
(
value
,
Messages
.
OSSPublish_MissingLocalPath
());
}
}
public
FormValidation
doCheckRemotePath
(
@QueryParameter
String
value
)
{
public
FormValidation
doCheckRemotePath
(
@QueryParameter
(
required
=
true
)
String
value
)
{
return
checkValue
(
value
,
Messages
.
OSSPublish_MissingRemotePath
());
return
checkValue
(
value
,
Messages
.
OSSPublish_MissingRemotePath
());
}
}
...
...
src/main/resources/org/inurl/jenkins/plugin/Messages_zh.properties
View file @
08f4e3fb
...
@@ -4,5 +4,5 @@ OSSPublish.MissingEndpoint=\u8bf7\u8bbe\u7f6eEndpoint
...
@@ -4,5 +4,5 @@ OSSPublish.MissingEndpoint=\u8bf7\u8bbe\u7f6eEndpoint
OSSPublish.MissingAccessKeyId
=
\u
8bf7
\u
8bbe
\u
7f6eAccessKeyId
OSSPublish.MissingAccessKeyId
=
\u
8bf7
\u
8bbe
\u
7f6eAccessKeyId
OSSPublish.MissingAccessKeySecret
=
\u
8bf7
\u
8bbe
\u
7f6eAccessKeySecret
OSSPublish.MissingAccessKeySecret
=
\u
8bf7
\u
8bbe
\u
7f6eAccessKeySecret
OSSPublish.MissingBucketName
=
\u
8bf7
\u
8bbe
\u
7f6eBucketName
OSSPublish.MissingBucketName
=
\u
8bf7
\u
8bbe
\u
7f6eBucketName
OSSPublish.MissingLocalPath
=
\u
8bf7
\u
8bbe
\u
7f6eLocalPath
OSSPublish.MissingLocalPath
=
\u
8bf7
\u
8bbe
\u
7f6e
\u
672c
\u5730\u
8def
\u
5f84
OSSPublish.MissingRemotePath
=
\u
8bf7
\u
8bbe
\u
7f6eRemotePath
OSSPublish.MissingRemotePath
=
\u
8bf7
\u
8bbe
\u
7f6e
\u
8fdc
\u
7a0b
\u
8def
\u
5f84
\ No newline at end of file
\ No newline at end of file
src/main/resources/org/inurl/jenkins/plugin/OSSPublisher/help-bucketName.html
0 → 100644
View file @
08f4e3fb
<div>
Aliyun OSS BucketName
<br/>
<a
target=
"_blank"
href=
"https://oss.console.aliyun.com"
>
config
</a>
</div>
src/main/resources/org/inurl/jenkins/plugin/OSSPublisher/help-remotePath.html
0 → 100644
View file @
08f4e3fb
<div>
Remote file or directory, must begin with `/`
</div>
\ No newline at end of file
src/test/java/org/inurl/jenkins/plugin/HelloWorldBuilderTest.java
deleted
100644 → 0
View file @
4713f40d
package
org.inurl.jenkins.plugin
;
import
hudson.model.FreeStyleBuild
;
import
hudson.model.FreeStyleProject
;
import
hudson.model.Label
;
import
org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition
;
import
org.jenkinsci.plugins.workflow.job.WorkflowJob
;
import
org.jenkinsci.plugins.workflow.job.WorkflowRun
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.jvnet.hudson.test.JenkinsRule
;
public
class
HelloWorldBuilderTest
{
@Rule
public
JenkinsRule
jenkins
=
new
JenkinsRule
();
final
String
name
=
"Bobby"
;
@Test
public
void
testConfigRoundtrip
()
throws
Exception
{
FreeStyleProject
project
=
jenkins
.
createFreeStyleProject
();
project
.
getBuildersList
().
add
(
new
HelloWorldBuilder
(
name
));
project
=
jenkins
.
configRoundtrip
(
project
);
jenkins
.
assertEqualDataBoundBeans
(
new
HelloWorldBuilder
(
name
),
project
.
getBuildersList
().
get
(
0
));
}
@Test
public
void
testConfigRoundtripFrench
()
throws
Exception
{
FreeStyleProject
project
=
jenkins
.
createFreeStyleProject
();
HelloWorldBuilder
builder
=
new
HelloWorldBuilder
(
name
);
builder
.
setUseFrench
(
true
);
project
.
getBuildersList
().
add
(
builder
);
project
=
jenkins
.
configRoundtrip
(
project
);
HelloWorldBuilder
lhs
=
new
HelloWorldBuilder
(
name
);
lhs
.
setUseFrench
(
true
);
jenkins
.
assertEqualDataBoundBeans
(
lhs
,
project
.
getBuildersList
().
get
(
0
));
}
@Test
public
void
testBuild
()
throws
Exception
{
FreeStyleProject
project
=
jenkins
.
createFreeStyleProject
();
HelloWorldBuilder
builder
=
new
HelloWorldBuilder
(
name
);
project
.
getBuildersList
().
add
(
builder
);
FreeStyleBuild
build
=
jenkins
.
buildAndAssertSuccess
(
project
);
jenkins
.
assertLogContains
(
"Hello, "
+
name
,
build
);
}
@Test
public
void
testBuildFrench
()
throws
Exception
{
FreeStyleProject
project
=
jenkins
.
createFreeStyleProject
();
HelloWorldBuilder
builder
=
new
HelloWorldBuilder
(
name
);
builder
.
setUseFrench
(
true
);
project
.
getBuildersList
().
add
(
builder
);
FreeStyleBuild
build
=
jenkins
.
buildAndAssertSuccess
(
project
);
jenkins
.
assertLogContains
(
"Bonjour, "
+
name
,
build
);
}
@Test
public
void
testScriptedPipeline
()
throws
Exception
{
String
agentLabel
=
"my-agent"
;
jenkins
.
createOnlineSlave
(
Label
.
get
(
agentLabel
));
WorkflowJob
job
=
jenkins
.
createProject
(
WorkflowJob
.
class
,
"test-scripted-pipeline"
);
String
pipelineScript
=
"node {\n"
+
" greet '"
+
name
+
"'\n"
+
"}"
;
job
.
setDefinition
(
new
CpsFlowDefinition
(
pipelineScript
,
true
));
WorkflowRun
completedBuild
=
jenkins
.
assertBuildStatusSuccess
(
job
.
scheduleBuild2
(
0
));
String
expectedString
=
"Hello, "
+
name
+
"!"
;
jenkins
.
assertLogContains
(
expectedString
,
completedBuild
);
}
}
\ 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