所以我在这方面取得了一些进展。它不是幂等的,但是可以。该代码是针对我的用例量身定制的,但对于您而言,自己进行调整也不应该太难。
import java.util.Arraysimport java.util.logging.LoggerLogger logger = Logger.getLogger("ecs-cluster")logger.info("Loading Jenkins")import jenkins.model.*instance = Jenkins.getInstance()import com.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate.MountPointEntrydef 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.ECSTaskTemplatedef 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.ECSCloudecsCloud = 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.cloudsclouds.add(ecsCloud)logger.info("Saving jenkins")instance.save()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)