如何用jenkins调用阿里云Java SDK

Java学习也比较讲究实战,很多人想知道jenkins共享库调用阿里云Java SDK,那么今天就给大家分享一下具体内容,希望对大家的学习有所帮助。

Grapes(

Grab(group='com.aliyun',module='aliyun-java-sdk-core',version='4.5.20')

)

import com.aliyuncs.CommonRequest;

import com.aliyuncs.CommonResponse;

import com.aliyuncs.DefaultAcsClient;

import com.aliyuncs.IAcsClient;

import com.aliyuncs.exceptions.ClientException;

import com.aliyuncs.exceptions.ServerException;

import com.aliyuncs.profile.DefaultProfile;

def setslb(name,conf){

//创建DefaultAcsClient实例并初始化

withCredentials([string(credentialsId:'alislb',variable:'slb')]){

def fname=sh(returnStdout:true,script:'echo${slb}').trim()

//some block

DefaultProfile profile=DefaultProfile.getProfile(

"cn-beijing",

"hhjhhgcvffhnn",

fname

);

IAcsClient client=new DefaultAcsClient(profile);

//创建API请求并设置参数

CommonRequest request=new CommonRequest();

request.setDomain("slb.aliyuncs.com");

request.setVersion("2014-05-15");

request.setAction("SetVServerGroupAttribute");

request.putQueryParameter("RegionId","cn-beijing");

request.putQueryParameter("VServerGroupId",name);

request.putQueryParameter("BackendServers",conf);

try{

CommonResponse response=client.getCommonResponse(request);

println(response.getData());

}catch(ServerException e){

//TODO Auto-generated catch block

//e.printStackTrace();

println(e.getMessage())

}catch(ClientException e){

//TODO Auto-generated catch block

//e.printStackTrace();

println(e.getMessage())

}

}

}

Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件项目可以进行持续集成。

(0)

相关推荐