Jenkins七牛插件覆盖上传

时间 : 15-10-03 栏目 : Jenkins, 集成测试 作者 : noway 评论 : 0 点击 : 993 次

最近想写一些android和iOS的demo,将demo放在博客上,随时进行更新。apk和ipa都通过Jenkins去编译,并上传到七牛上,由七牛提供下载的连接地址。

因为免费的七牛空间有限,不能每次编译我都向上面传一个免费的包。

发现原先项目中的七牛插件并不能覆盖上传。

发现七牛的后台也没有关于覆盖上传的设置。

经过实践尝试,整理一下笔记:

七牛文档

http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html#put-policy-scope

scope

指定上传的目标资源空间(Bucket)和资源键名(Key)。
有两种格式:
● <bucket>,表示允许用户上传文件到指定的 bucket。在这种格式下文件只能“新增”,若已存在同名资源则会失败。
● <bucket>:<key>,表示只允许用户上传指定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

除非注明,文章均为( noway )原创,转载请保留链接: http://blog-old.z3a105.com/?p=593

Jenkins七牛插件覆盖上传:等您坐沙发呢!

发表评论





       ==QQ:122320466==

 微信    QQ群


0

Aujourd’hui, une partie avec le développement du e-commerce, achats en ligne est devenu une partie de la vie pour beaucoup de gens. La mariage a commencé achats en ligne. Si vous choisissez achats les mariages en ligne, il peut être beaucoup moins cher que le salon de la Robe de mariée pas chermariée local, réduisant le budget de mariage. vous pouvez avoir beaucoup de choix si acheter de mariage en ligne. vous pouvez ramasser une robe de mariée bon marché sur Internet.
Piercing fascinerande figur, och nu tittar vi på 2016 senast brudklänning, kan du vara den vackraste bruden det!2016 senaste Bra brudklänning, söt temperament Bra design, romantiska spetsar blomma kjol, som du lägger till en elegant och charmig temperament.Kvinnan tillbaka mjuka linjer, människor brudklänningofta få en känsla av oändlig frestelse. Fall 2016 mässan, lämnar uppgifter om ditt bröllop charmig.
Yesterday afternoon, the Chinese team was training in the Guangzhou Gymnasium, when the reporter asked Zhao Yunlei the feeling of wearing the new cheap jersey , cheap jerseys online shopshe readily took a shirt from the bag crumpled ball to reporters, and she said with a smile: ” This shirt is light. ”Zhao Yunlei said: “Our material is very light like with the clothes of the tennis King Nadal, Federer, after the sweat, sweat does not drip down to the ground, when we do move, it is easy pace slipping if the sweat drip on the floor.”Tennis players Zhang Yawen, told reporters: “You might think the clothes attached to the body, fearing we swing will be affected, in fact, we do not feel anything, because the clothes are very light, very soft, put on quite comfortable. And it’s particularly good clothes to dry, washing and will dry in 15 minutes. ”
China’s sports enthusiasts NFL sweatshirt with mad love and the pursuit of, and therefore, NFL jerseys have a good market in China and development. China is a populous country, is the consumer, the economic momentum is so good, the sales prospects sportswear is immeasurable. With hot sales sweatshirt, but also to promote the importance of sports fans, on health, on the other hand is a matter of concern for the World Cup, fans wearing NFL jerseys and also can express themselves more fully love and obsession Therefore, NFL jerseys Wholesale jerseys online shopwholesale has good prospects and development in China.
ANTA-ANTA Sports Products Limited, referred to as ANTA Sports, Anta, is China’s leading sporting goods companies, mainly engaged in the design, development, manufacture and marketing of ANTA brand sporting goods, including sports footwear, apparel and accessories. Anta sweatshirt design advantages, warm stretch knit fabric, using Slim version of model, more personal fit, bid farewell to bloated, so wearing more stylish.GUIRENNIAO-This logo is a spiritual totem, smooth graphics implication unstoppable force; flexible deliver an elegant arc Wholesale jerseys china shop movement, strength and speed of the United States, a symbol of passion and rationality publicity “Heart” and “meaning”, “concept” unity; pass the fearless and enterprising mind, showing beyond the realm of self, to unstoppable force to create the future.XTEP-Xtep (China) Co., Ltd. is a comprehensive development wholesale jerseys china shop, production and marketing of Xtep brand (XTEP) sports shoes, clothing, bags, caps, balls, socks mainly large sporting goods industry enterprises.
There are a lot of fans in identifying the authenticity of the above cheap jerseys have great distress, so here to i will show you some methods to definitely affordable inexpensive cheap jerseys : Firstly, we should look at if it is working fine. China has been called the world’s factory, a lot cheap jerseys factories in China have foundries, but our cheap jerseys are all from here! Secondly, should to see whether it is the , we all know that it is difficult to get out of print once a genuine cheap cheap jerseys free shipping jersey was print. and we have all kind of stocka on the whole website, in other words, we have all you want ! Finally, look at the price, our price is not necessarily the lowest in the whole website but it must be most fair on the whole website, we certainly you will not regret later when you buy it. Of course, except that cheap jerseys, we also have the other products, such as socks, leggings and some other related products, everyone can enjoy the best services of here!

KUBET