scope
指定上传的目标资源空间(Bucket)和资源键名(Key)。
有两种格式:
●
,表示允许用户上传文件到指定的 bucket。在这种格式下文件只能“新增”,若已存在同名资源则会失败。
●
,表示只允许用户上传指定key的文件。在这种格式下文件默认允许“修改”,已存在同名资源则会被本次覆盖。如果希望只能上传指定key的文件,并且不允许修改,那么可以将下面的 insertOnly
属性值设为 1
。
insertOnly
限定为“新增”语意。
如果设置为非0值,则无论scope设置为什么形式,仅能以新增
模式上传文件。
Jenkins插件
@Override
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener)
throws IOException, InterruptedException {
PrintStream logger = listener.getLogger();
String accessKey = this.getDescriptor().getAccessKey();
String secretKey = this.getDescriptor().getSecretKey();
FilePath ws = build.getWorkspace();
if (build.getResult() == Result.FAILURE) {
logger.println("Build failed, don't perform uploading ......");
return false;
}
logger.println("Start to upload to Qiniu ......");
Mac mac = new Mac(accessKey, secretKey);
PutPolicy putPolicyGlobal = new PutPolicy(this.getBucket());
String uptoken;
PutExtra extra = new PutExtra();
String includes = this.getFolder() + File.separator + "*" + this.getExt();
FilePath[] paths = ws.list(includes);
boolean rtnFlag = false;
for (FilePath path : paths) {
String name = path.getName();
putPolicyGlobal.insertOnly=0;
putPolicyGlobal.scope=this.getBucket()+":"+name;
String fileName2Upload = path.getRemote();
try {
uptoken = putPolicyGlobal.token(mac);
PutRet ret = IoApi.putFile(uptoken, name, new File(fileName2Upload), extra);
JSONObject retJsonObject = (JSONObject) JSONSerializer.toJSON(ret.toString());
if (ret.ok()) {
rtnFlag = true;
logger.println("Finish uploading, file: " + name + ", return: "
+ retJsonObject.getString("key"));
} else {
rtnFlag = false;
logger.println("Upload failed, file: " + name + ", cuz: "
+ retJsonObject.getString("error"));
}
} catch (Exception e) {
logger.println(e.getMessage());
build.setResult(Result.UNSTABLE);
}
}
logger.println("Uploading to Qiniu over ......");
return rtnFlag;
}
重新编译生产.hpi
Jenkins自定义插件安装
运行Jenkins
+ mv iDemo_V1_Debug.ipa iDemo_V1_Release_B97c4d3e5.ipa + cp iDemo_V1_Release_B97c4d3e5.ipa iDemo.ipa Start to upload to Qiniu ...... Finish uploading, file: iDemo.ipa, return: iDemo.ipa Uploading to Qiniu over ...... Email was triggered for: Success Sending email for trigger: Success ----------------------------- ok
评论区