我正在尝试使用import jenkins.model.*
import com.cloudbees.jenkins.plugins.amazonecs.*
ECSCloud.metaClass.properties.each {println it.name+":\t"+it.type }
脚本为Jenkins配置amazon-ecs-plugin,但无法在其上找到和使用docs。我是基于groovy的配置自动化的新手
尝试使用
获取所有属性regionName: class java.lang.String
searchName: class java.lang.String
slaveTimoutInSeconds: int
searchIndex: interface hudson.search.SearchIndex
ACL: class hudson.security.ACL
descriptor: class hudson.model.Descriptor
credentialsId: class java.lang.String
search: class hudson.search.Search
ecsService: class com.cloudbees.jenkins.plugins.amazonecs.ECSService
class: class java.lang.Class
searchUrl: class java.lang.String
tunnel: class java.lang.String
templates: interface java.util.List
cluster: class java.lang.String
jenkinsUrl: class java.lang.String
amazonECSClient: class com.amazonaws.services.ecs.AmazonECSClient
displayName: class java.lang.String
输出:
ecsService: class com.cloudbees.jenkins.plugins.amazonecs.ECSService
但是,不知道如何继续像子类一样
def ecs-cloud = new ECSCloud(
regionName="String"
ecsService="<NOT SURE HOT TO CONFIGURE THIS>"
......
)
不确定,如何定义该属性
.xml
手动配置后的<clouds>
<com.cloudbees.jenkins.plugins.amazonecs.ECSCloud plugin="scalable-amazon-ecs@1.0">
<name>ECS-CLUSTER-NAME</name>
<templates>
<com.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate>
<label>jnlp-slave</label>
<image>jenkinsci/jnlp-slave</image>
<remoteFSRoot>/home/jenkins</remoteFSRoot>
<memory>800</memory>
<cpu>800</cpu>
<privileged>false</privileged>
<taskDefinitionArn>TASK-DEF-ARN</taskDefinitionArn>
</com.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate>
</templates>
<credentialsId></credentialsId>
<cluster>arn:aws:ecs:REGION:ACCOUNTID:cluster/ECS-CLUSTER-NAME</cluster>
<regionName>REGION</regionName>
<tunnel></tunnel>
<jenkinsUrl>JENKINS-URL</jenkinsUrl>
<slaveTimoutInSeconds>900</slaveTimoutInSeconds>
<ecsService>
<credentialsId></credentialsId>
<regionName>REGION</regionName>
</ecsService>
</com.cloudbees.jenkins.plugins.amazonecs.ECSCloud>
</clouds>
文件如
{{1}}
提前致谢。
my 使用EC2插件的类似问题。
答案 0 :(得分:2)
所以我在这方面取得了一些进展。它不是幂等的,但它有效。该代码是根据我的用例量身定制的,但是对于您自己的调整来说不应该太难。
import java.util.Arrays
import java.util.logging.Logger
Logger logger = Logger.getLogger("ecs-cluster")
logger.info("Loading Jenkins")
import jenkins.model.*
instance = Jenkins.getInstance()
import com.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate.MountPointEntry
def mounts = Arrays.asList(
new MountPointEntry(
name="docker",
sourcePath="/var/run/docker.sock",
containerPath="/var/run/docker.sock",
readOnly=false),
new MountPointEntry(
name="jenkins",
sourcePath="/home/jenkins",
containerPath="/home/jenkins",
readOnly=false),
)
logger.info("Creating template")
import com.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate
def ecsTemplate = new ECSTaskTemplate(
templateName="jnlp-slave-with-docker",
label="ecs-with-docker",
image="jnlp-slave-with-docker:latest",
remoteFSRoot=null,
memory=2048,
cpu=512,
privileged=false,
logDriverOptions=null,
environments=null,
extraHosts=null,
mountPoints=mounts
)
logger.info("Retrieving ecs cloud config by descriptor")
import com.cloudbees.jenkins.plugins.amazonecs.ECSCloud
ecsCloud = new ECSCloud(
name="name",
templates=Arrays.asList(ecsTemplate),
credentialsId=null,
cluster="arn:aws:ecs:us-east-1:123456789:cluster/ecs-jenkins-slave",
regionName="us-east-1",
jenkinsUrl="https://my-jenkins.com",
slaveTimoutInSeconds=60
)
logger.info("Gettings clouds")
def clouds = instance.clouds
clouds.add(ecsCloud)
logger.info("Saving jenkins")
instance.save()
答案 1 :(得分:0)
上述答案中的ECSTaskTemplate不再有效。 memoryReservation丢失了。
以下是ECSTaskTemplate
def ecsTemplate = new ECSTaskTemplate(
templateName="jnlp-slave",
label="ecs",
image="jenkinsci/jnlp-slave",
remoteFSRoot=null,
memory=0,
memoryReservation=2048,
cpu=512,
privileged=false,
logDriverOptions=null,
environments=null,
extraHosts=null,
mountPoints=null
)