jenkinsci / amazon-ecs-plugin

Amazon EC2 Container Service Plugin for Jenkins
https://plugins.jenkins.io/amazon-ecs
MIT License
192 stars 226 forks source link

When defining a capacity provider the "capacityProviderStrategies" parameter is not valid. #268

Closed morfien101 closed 2 years ago

morfien101 commented 2 years ago

Jenkins and plugins versions report

Environment Jenkins 2.346.2 Amazon Elastic Container Service (ECS) / Fargate plugin Version1.41 ```text WARNING: Unknown parameter(s) found for class type 'com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStep': capacityProviderStrategies ```

What Operating System are you using (both controller, and any agents involved in the problem)?

Ubuntu 22.04

Reproduction steps

When writing a dynamic agent using the example code:

import com.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate
ecsTaskTemplate(
      capacityProviderStrategies: [new ECSTaskTemplate.CapacityProviderStrategyEntry('FARGATE_SPOT',0,50), new ECSTaskTemplate.CapacityProviderStrategyEntry('FARGATE',0,1)]
    ) {
        node(labelValue) {
            stage('run aws tasks') {
                sh 'echo "Hello World"'
            }
        }
    }

Expected Results

The capacity provider is added to the task

Actual Results

An error is given in the jenkins log: WARNING: Unknown parameter(s) found for class type 'com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStep': capacityProviderStrategies

Anything else?

As a side note, when using the Jenkins Pipeline Syntax page, I get the following error:

no public field ‘capacityProviderStrategy’ (or getter method) found in class com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStep

morfien101 commented 2 years ago

@chathsuom I was looking in the old pull requests and seen that you put in the feature for capacity.

I think the issue is that the getter and setter methods are the wrong names. It's never used in the tests so I doubt it would ever have been noticed.

// The Setter
public void setCapacityProviderStrategy(List<CapacityProviderStrategyEntry> capacityProviderStrategies)

// The Getter
public List<CapacityProviderStrategyEntry> getCapacityProviderStrategies()

Specifically the issue of CapacityProviderStrategy and CapacityProviderStrategies

https://github.com/jenkinsci/amazon-ecs-plugin/blob/master/src/main/java/com/cloudbees/jenkins/plugins/amazonecs/pipeline/ECSTaskTemplateStep.java#L429

morfien101 commented 2 years ago

I can confirm a work around for now is you use the wrong syntax.

import com.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate
ecsTaskTemplate(
      // Use capacityProviderStrategy rather than capacityProviderStrategies here.
      capacityProviderStrategy: [new ECSTaskTemplate.CapacityProviderStrategyEntry('FARGATE_SPOT',0,50), new ECSTaskTemplate.CapacityProviderStrategyEntry('FARGATE',0,1)]
    ) {
        node(labelValue) {
            stage('run aws tasks') {
                sh 'echo "Hello World"'
            }
        }
    }
chathsuom commented 2 years ago

Hi @morfien101 Good call out. Feel free to do a PR.

Stericson commented 2 years ago

Merged, thanks!