Configure Jenkins EC2-Plugin with Groovy

I am trying to configure the Jenkins EC2-Plugin via Groovy.
Plugin code: https://github.com/jenkinsci/ec2-plugin

I’m trying to setup the cloud with a name to get started

  • Make Github push to a remote server when it receives updates
  • AWS CodePipeline, build failed & getting error as YAML_FILE_ERROR M
  • SSH into EC2 and can't execute git clone command
  • Elastic Beanstalk, Git and AWS Tools: How to clone repository to another workstation
  • chef deployment?
  • Can't push to repository on EC2 - Could not resolve hostname
  • import hudson.model.*
    import jenkins.model.*
    import hudson.plugins.ec2.*
    import com.amazonaws.services.ec2.model.*
    
    SlaveTemplate awsTemplate = new SlaveTemplate(
      'ami-1234567',
      '',
      '',
      'sg-1234567',
      't2.micro',
      true,
      'foo',
      '',
      'stuff',
      'run code',
      '/var/tmp',
      'more code',
      '4',
      '',
      '',
      '',
      false,
      'subnet-1234567',
      '',
      '60',
      false,
      '',
      'iam-profile',
      false,
      false,
      '',
      false,
      '',
      true,
      false
    )
    
    def slaveTemplates = [awsTemplate]
    
    def ec2Cloud = new AmazonEC2Cloud(
      'foo',
      true,
      '',
      'us-west-2',
      '',
      '10',
      slaveTemplates
    )
    
    def cloudList = Jenkins.instance.clouds
    cloudList.add(ec2Cloud)
    

    Any ideas?

    These are the error messages

    Error: Could not find matching constructor for: hudson.plugins.ec2.SlaveTemplate
    

    or

    Error: Could not find matching constructor for: hudson.plugins.ec2.AmazonEC2Cloud
    

  • Couldn't find any revision to build. Verify the repository and branch configuration for this job. Finished: FAILURE
  • Jenkins path to git Windows master / Linux slave
  • Can't store sh command output through DSL (groovy) in Jenkins pipeline job
  • Jenkins Build Periodically - Schedule
  • Add SonarQube to jenkins job pipeline failed
  • Attempting to use scm:tag in a Jenkins job for a Git repository that requires a username/password
  • 2 Solutions collect form web for “Configure Jenkins EC2-Plugin with Groovy”

    Your call to SlaveTemplate does not match any of the constructors: https://github.com/jenkinsci/ec2-plugin/blob/master/src/main/java/hudson/plugins/ec2/SlaveTemplate.java

    For example, the third parameter (spotConfig) is looking for a SpotConfiguration object. You currently have an empty string defined there. (You can replace that with null.)

    Also, the instance-type parameter should be an InstanceType, not a string. To correct that, you’ll want to add import com.amazonaws.services.ec2.model.InstanceType to the top of the groovy script and replace 't2.micro' with InstanceType.fromValue('t2.micro').

    For a full example, see https://gist.github.com/vrivellino/97954495938e38421ba4504049fd44ea

    For starters, the only constructor available for this class has the following signature:

    public AmazonEC2Cloud(
      String cloudName, 
      boolean useInstanceProfileForCredentials, 
      String credentialsId, 
      String region, 
      String privateKey, 
      String instanceCapStr, 
      List<? extends SlaveTemplate> templates
    )
    
    Git Baby is a git and github fan, let's start git clone.