Coder Social home page Coder Social logo

amazon-ecs-plugin's Introduction

Amazon Elastic Container Service (ECS / Fargate) Plugin for Jenkins

Build Status Join the chat at https://gitter.im/jenkinsci/amazon-ecs-plugin

About

This Jenkins plugin uses Amazon Elastic Container Service to host jobs execution inside docker containers.

Jenkins delegates to Amazon ECS the execution of the builds on Docker based agents. Each Jenkins build is executed on a dedicated Docker container that is wiped-out at the end of the build.

Installation & configuration

The scope of the plugin is only using existing and pre-configured AWS Infrastructure. It does not create any of the needed infrastructure on its own. Use tools like CloudFormation or Terraform for this task.

Requirements

  • Jenkins with at least version 2.289.1
  • AWS Account

Plugin install

Use the Jenkins plugin manager to install the Amazon Elastic Container Service plugin

Configuration

Examples

There are currently the following example setups in this repo:

Additionally there is an example setup here: Terraform Jenkins AWS ECS Fargate

Amazon ECS cluster

As a pre-requisite, you must have created an Amazon ECS cluster with associated ECS instances. These instances can be statically associated with the ECS cluster or can be dynamically created with Amazon Auto Scaling.

The Jenkins Amazon EC2 Container Service plugin will use this ECS cluster and will create automatically the required Task Definition.

Jenkins System Configuration

Navigate to the "Configure System" screen.

In the "Jenkins Location" section, ensure that the "Jenkins URL" is reachable from the the container instances of the Amazon ECS cluster. See the section "Network and firewalls" for more details.

If the global Jenkins URL configuration does not fit your needs (e.g. if your ECS agents must reach Jenkins through some kind of tunnel) you can also override the Jenkins URL in the Advanced Configuration of the ECS cloud.

At the bottom of the screen, click on "Add a new Cloud" and select "Amazon EC2 Container Service Cloud".

Amazon EC2 Container Service Cloud

Then enter the configuration details of the Amazon EC2 Container Service Cloud:

  • Name: name for your ECS cloud (e.g. ecs-cloud)
  • Amazon ECS Credentials: Amazon IAM Access Key with privileges to create Task Definitions and Tasks on the desired ECS cluster
  • ECS Cluster: desired ECS cluster on which Jenkins will send builds as ECS tasks
  • ECS Template: click on "Add" to create the desired ECS template or templates

Advanced configuration

  • Tunnel connection through: tunnelling options (when Jenkins runs behind a load balancer).
  • Alternative Jenkins URL: The URL used as the Jenkins URL within the ECS containers of the configured cloud. Can be used to override the default Jenkins URL from global configuration if needed.
ECS Agent Templates

One or several ECS agent templates can be defined for the Amazon EC2 Container Service Cloud. The main reason to create more than one ECS agent template is to use several Docker images to perform build (e.g. java-build-tools, php-build-tools...)

  • Template name is used (prefixed with the cloud's name) for the task definition in ECS.
  • Label: agent labels used in conjunction with the job level configuration "Restrict where the project can be run / Label expression". ECS agent label could identify the Docker image used for the agent (e.g. docker for the jenkinsci/inbound-agent). Multiple, space delimited labels can be specified(e.g. java11 alpine). Label expressions within a job such as java11 && alpine or java11 || alpine are not currently supported.
  • Filesystem root: working directory used by Jenkins (e.g. /home/jenkins/).
  • Memory: number of MiB of memory reserved for the container. If your container attempts to exceed the memory allocated here, the container is killed.
  • CPU units: number of cpu units to reserve for the container. A container instance has 1,024 cpu units for every CPU core.

Advanced Configuration

  • Override entrypoint: overwritten Docker image entrypoint. Container command can't be overriden as it is used to pass jenkins agent connection parameters.
  • JVM arguments: additional arguments for the JVM, such as -XX:MaxPermSize or GC options.

Network and firewalls

Running the Jenkins master and the ECS container instances in the same Amazon VPC and in the same subnet is the simplest setup and default settings will work out-of-the-box.

Firewalls If you enable network restrictions between the Jenkins master and the ECS cluster container instances,

  • Fix the TCP listen port for JNLP agents of the Jenkins master (e.g. 5000) navigating in the "Manage Jenkins / Configure Global Security" screen
  • Allow TCP traffic from the ECS cluster container instances to the Jenkins master on the listen port for JNLP agents (see above) and the HTTP(S) port.

Network Address Translation and Reverse Proxies In case of Network Address Translation rules between the ECS cluster container instances and the Jenkins master, ensure that the JNLP agents will use the proper hostname to connect to the Jenkins master doing on of the following:

  • Define the proper hostname of the Jenkins master defining the system property hudson.TcpSlaveAgentListener.hostName in the launch command
  • Use the advanced configuration option "Tunnel connection through" in the configuration of the Jenkins Amazon EC2 Container Service Cloud (see above).

IAM Permissions

To work the plugin needs some IAM permissions. Assign a role with those permissions to the instance / container you are running the master on.

Here is an example of a role in CloudFormation, make sure to modify it for your needs.

TaskRole:
    Type: AWS::IAM::Role
    Properties:
        RoleName: !Sub ${AWS::StackName}-task-role
        Path: /
        AssumeRolePolicyDocument:
            Version: 2012-10-17
            Statement:
                - Effect: Allow
                  Principal:
                      Service:
                          - ecs-tasks.amazonaws.com
                  Action: sts:AssumeRole
        Policies:
            - PolicyName: !Sub ecs-${AWS::StackName}
              PolicyDocument:
                  Version: "2012-10-17"
                  Statement:
                      - Action:
                            - "ecs:RegisterTaskDefinition"
                            - "ecs:ListClusters"
                            - "ecs:DescribeContainerInstances"
                            - "ecs:ListTaskDefinitions"
                            - "ecs:DescribeTaskDefinition"
                            - "ecs:DeregisterTaskDefinition"
                            - "ecs:ListTagsForResource"
                        Effect: Allow
                        Resource: "*"
                      - Action:
                            - "ecs:ListContainerInstances"
                            - "ecs:DescribeClusters"
                        Effect: Allow
                        Resource:
                            - !Sub "arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:cluster/<clusterName>"
                      - Action:
                            - "ecs:RunTask"
                        Effect: Allow
                        Condition:
                            ArnEquals:
                                ecs:cluster:
                                    - !Sub "arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:cluster/<clusterName>"
                        Resource: !Sub "arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:task-definition/*"
                      - Action:
                            - "ecs:StopTask"
                        Effect: Allow
                        Condition:
                            ArnEquals:
                                ecs:cluster:
                                    - !Sub "arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:cluster/<clusterName>"
                        Resource: !Sub "arn:aws:ecs:*:*:task/*" # "arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:task/*"
                      - Action:
                            - "ecs:DescribeTasks"
                        Effect: Allow
                        Condition:
                            ArnEquals:
                                ecs:cluster:
                                    - !Sub "arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:cluster/<clusterName>"
                        Resource: !Sub "arn:aws:ecs:*:*:task/*" # "arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:task/*"
                      - Action:
                            - "elasticfilesystem:DescribeAccessPoints"
                            - "elasticfilesystem:DescribeFileSystems"
                        Effect: Allow
                        Resource: !Sub "arn:aws:elasticfilesystem:${AWS::Region}:${AWS::AccountId}:file-system/*"

Agent

The Jenkins Amazon EC2 Container Service Cloud can use for the agents all the Docker image designed to act as a Jenkins JNLP agent. Here is a list of compatible Docker images:

You can easily extend the images or also build your own.

Declarative Pipeline

Declarative Pipeline support requires Jenkins 2.66+

Declarative agents can be defined like shown below. You can also reuse pre-configured templates and override certain settings using inheritFrom to reference the Label field of the template that you want to use as preconfigured. Only one label is expected to be specified.

When using inheritFrom, the label will not copied. Instead, a new label will be generated based on the following schema {job-name}-{job-run-number}-{5-random-chars} e.g. "pylint-543-b4f42". This guarantees that there will not be conflicts with the parent template or other runs of the same job, as well as making it easier to identify the labels in Jenkins.

If you want to override the label, ensure that you are not going to conflict with other labels configured elsewhere. Templates for dynamic agents exist until the agent dies, meaning other jobs requesting the same label (including dynamic agents on other runs of the same job!) run the chance of provisioning the dynamic agent's ECSTask.

Note: You have to configure list of settings to be allowed in the declarative pipeline first (see the Allowed Overrides setting). They are disabled by default for security reasons, to avoid non-privileged users to suddenly be able to change certain settings.

If Jenkins is unexpectedly shut down there is a good chance that ECS Tasks for dynamic agents will not be cleaned up (de-registered) in AWS. This should not cause issues, but may come as a surprise when looking at the console.

Usage

The ECS agents can be used for any job and any type of job (Freestyle job, Maven job, Workflow job...), you just have to restrict the execution of the jobs on one of the labels used in the ECS Agent Template configuration. You can either restrict the job to run on a specific label only via the UI or directly in the pipeline.

pipeline {
  agent none

  stages {
       stage('PublishAndTests') {
          environment {
              STAGE='prod'
          }
          agent {
            label 'build-python36'
          }
      }
      steps {
        sh 'java -version'
      }
    }
  }
pipeline {
  agent none

  stages {
    stage('Test') {
        agent {
            ecs {
                inheritFrom 'label-of-my-preconfigured-template'
                cpu 2048
                memory 4096
                image '$AWS_ACCOUNT.dkr.ecr.$AWS_REGION.amazonaws.com/jenkins/java8:2019.7.29-1'
                logDriver 'fluentd'
                logDriverOptions([[name: 'foo', value:'bar'], [name: 'bar', value: 'foo']])
                portMappings([[containerPort: 22, hostPort: 22, protocol: 'tcp'], [containerPort: 443, hostPort: 443, protocol: 'tcp']])
            }
        }
        steps {
            sh 'echo hello'
        }
    }
  }
}

Scripted Pipeline examples

def dynamic_label = "${JOB_NAME}_${env.sha}"
ecsTaskTemplate(
    cloud: 'CloudNameAsConfiguredInManageClouds',
    label: dynamic_label,
    name: dynamic_label, // Reusing the label as a name makes sense as long as it's unique
    containerUser: 'ubuntu',
    remoteFSRoot: '/home/ubuntu',
    overrides: [],
    agentContainerName: 'java',    
    taskDefinitionOverride: "arn:aws:redacted:redacted:task-definition/${env.task}"
) {
  node(dynamic_label) {
    stage("I dunno why you say goodbye"){
      sh 'echo hello'
    }
  }
}
pipeline{
    agent {
        ecs {
          inheritFrom 'ecs_test'
          cpu 1000
        } 
    }
    stages{
        stage("Here goes nothin"){
          sh 'echo hello'
        }
    }
}

FAQ

My parallel jobs don't start at the same time

Actually, there can be multiple reasons:

  • The plugin creates a new agent only when the stage contains an agent definition. If this is missing, the stage inherits the agent definition from the level above and also re-uses the instance.

  • Also, parallel stages sometimes don't really start at the same time. Especially, when the provided label of the agent definition is the same. The reason is that Jenkins tries to guess how many instances are really needed and tells the plugin to start n instances of the agent with label x. This number is likely smaller than the number of parallel stages that you've declared in your Jenkinsfile. Jenkins calls the ECS plugin multiple times to get the total number of agents running.

  • If launching of the agents takes long, and Jenkins calls the plugin in the meantime again to start n instances, the ECS plugin doesn't know if this instances are really needed or just requested because of the slow start. That's why the ECS plugin subtracts the number of launching agents from the number of requested agents (for a specific label). This can mean for parallel stages that some of the agents are launched after the previous bunch of agents becomes online.

There are options that influence how Jenkins spawns new Agents. You can set for example on your master the following to improve the launch times:

-Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85

Who runs this & Resources

If you are running a interesting setup or have public posts abour your setups using this plugins, please file a PR to get it added here.

Maintainers

Andreas Sieferlinger (GitHub Twitter)
Philipp Garbe (GitHub, Twitter)
Marky Jackson (GitHub, Twitter)
Stephen Erickson (GitHub)

Developing

Building the Plugin

  java -version # Need Java 1.8, earlier versions are unsupported for build
  mvn -version # Need a modern maven version; maven 3.2.5 and 3.5.0 are known to work
  mvn clean install

Running locally

To run locally, execute the following command and open the browser http://localhost:8080/jenkins/

  mvn -e hpi:run

Debugging the plugin in an editor

IntelliJ IDEA

In the Maven dialog right click hpi:run and select Debug. The IDE will stop at any breakpoints you have set inside the plugin.

Other

the

    @Rule
    public JenkinsRule j = new JenkinsRule();

Will actually invoke code that will bootstrap a local installation of jenkins.war. This will allow you to debug with with breakpoints and such. However, to do it you will need to set some system properties or be aware how it tries to auto-configure. It will attempt to look for a .jenkins directory recursively with an already exploded war, So, theoretically you explode it, and git ignore it, right in this space. Alternatively, you can set a System property: -Djth.jenkins-war.path=${PATH}/jenkins.war

Make sure to include this rule in any tests that touch Jenkins specific resources like: Jenkins.instance()

Releasing the Plugin

 mvn clean release:prepare release:perform

further checks to aid with development

Check for additional or forgotten dependencies:

mvn dependency:analyze

Check if javadoc works fine (usually only executed on release)

mvn org.apache.maven.plugins:maven-javadoc-plugin:2.10.4:jar

amazon-ecs-plugin's People

Contributors

arus2023 avatar ascheman avatar bachiri avatar bruecktech avatar carlosrodf avatar chb0github avatar cyrille-leclerc avatar daveygit2050 avatar dependabot[bot] avatar flah00 avatar francoiscampbell avatar markjacksonfishing avatar mbaitelman avatar meebok avatar mseelye avatar mvallim avatar ndeloof avatar nullify005 avatar pgarbe avatar pgmillon avatar roehrijn avatar saad352 avatar stericson avatar tkgregory avatar ugurkanyenigun avatar vladaurosh avatar webratz avatar wenduwan avatar wmpbar avatar wuillaum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

amazon-ecs-plugin's Issues

Declarative Agent Declaration Skips Default Checkout

It appears that when defining an agent using the declarative syntax, the default checkout functionality that comes with declarative pipelines is disabled.

I suspect the issue might be in com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSDeclarativeAgentScript but can't be certain. That class appears to import org.jenkinsci.plugins.pipeline.modeldefinition.agent.CheckoutScript but does not do anything with it.

There is a simple enough workaround (explicitly disable default checkout and add a checkout stage):

pipeline {
  agent {
    ecs {
      inheritFrom 'my-base-agent-label'
      label 'my-custom-agent-label'
    }
  }

  options {
    skipDefaultCheckout()
  }

  stages {
    stage ('Checkout') {
      steps {
        checkout scm
      }
    }

    ...more stages for the pipeline...

  }
}

Obviously it would be preferred though if the default checkout functionality was preserved when using a declarative definition for an ECS agent.

Error Removing Dynamic Templates

Getting a NPE after upgrading to version 1.21.

Looks like when it calls String parentLabel = taskTemplate.getInheritFrom(); its null as it is a nullable value and when it calls String customTaskDefinition = ecsCloud.isCustomTaskDefinition(parentLabel); the getTemplate(label) in the method throws the NPE.

Suggested fix it to check if parentLabel is null before checking isCustomTaskDefinition(parentLabel)

java.lang.NullPointerException at com.cloudbees.jenkins.plugins.amazonecs.ECSCloud.isCustomTaskDefinition(ECSCloud.java:182) at com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution$ECSTaskTemplateCallback.finished(ECSTaskTemplateStepExecution.java:186) at org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback$TailCall.onSuccess(BodyExecutionCallback.java:118) at org.jenkinsci.plugins.workflow.cps.CpsBodyExecution$SuccessAdapter.receive(CpsBodyExecution.java:377) at com.cloudbees.groovy.cps.Outcome.resumeFrom(Outcome.java:73) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:166) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163) at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129) at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268) at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51) at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:186) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:370) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:93) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:282) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:270) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:66) at java.util.concurrent.FutureTask.run(Unknown Source) at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Finished: FAILURE

Default Docker image in Docker Hub was changed

After plugin installation the ECS agent templates -> Docker Image contains already pre-set default value of: jenkinsci/jnlp-slave
However, if you visit the Hub page, it stated that this image is deprecated and it is suggested to use new Hub jenkins/jnlp-slave

So need to replace default value to the new recommended image URL
Additionally, update info hint on the settings page which is reflected in help-image.html file

Fargate agent stuck "Waiting for agent to connect"

I'm working through setting this up, but I am unable to run the suggested sample pipeline from

cloudbees/jnlp-slave-with-java-build-tools

node ("jenkins-ecs-worker") {
    git "https://github.com/cloudbees-community/game-of-life"
    withMaven(mavenSettingsConfig:'my-maven-settings') {
       sh "mvn clean deploy"
    }
}

The ECS Fargate worker appears to start fine but never connects:

2019-06-11 14:03:19.003+0000 [id=42]	INFO	c.c.j.plugins.amazonecs.ECSCloud#provision: Asked to provision 1 agent(s) for: jenkins-ecs-worker
2019-06-11 14:03:19.003+0000 [id=42]	INFO	c.c.j.plugins.amazonecs.ECSCloud#provision: In provisioning : []
2019-06-11 14:03:19.003+0000 [id=42]	INFO	c.c.j.plugins.amazonecs.ECSCloud#provision: Excess workload after pending ECS agents: 1
2019-06-11 14:03:19.003+0000 [id=42]	INFO	c.c.j.plugins.amazonecs.ECSCloud#provision: Will provision ECS Agent jenkins-ecs-worker, for label: jenkins-ecs-worker
2019-06-11 14:03:19.003+0000 [id=42]	INFO	h.s.NodeProvisioner$StandardStrategyImpl#apply: Started provisioning ECS Agent jenkins-ecs-worker from jenkins-build-cluster with 1 executors. Remaining excess workload: 0
2019-06-11 14:03:29.020+0000 [id=40]	INFO	hudson.slaves.NodeProvisioner$2#run: ECS Agent jenkins-ecs-worker provisioning successfully completed. We have now 2 computer(s)
2019-06-11 14:03:29.191+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSService#registerTemplate: Match on container definition: true
2019-06-11 14:03:29.191+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSService#registerTemplate: Match on volumes: true
2019-06-11 14:03:29.191+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSService#registerTemplate: Match on task role: true
2019-06-11 14:03:29.191+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSService#registerTemplate: Match on execution role: true
2019-06-11 14:03:29.191+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSService#registerTemplate: Match on network mode: true
2019-06-11 14:03:29.191+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#runECSTask: [jenkins-build-cluster-pbxr1]: Starting agent with task definition arn:aws:ecs:us-east-1:435433059373:task-definition/jenkins-build-cluster-jenkins-ecs-worker:4}
2019-06-11 14:03:29.885+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#runECSTask: [jenkins-build-cluster-pbxr1]: Agent started with task arn : arn:aws:ecs:us-east-1:435433059373:task/jenkins-build-cluster/ba7c88b826114baa8b7e864a0fe3faa3
2019-06-11 14:03:29.885+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: TaskArn: arn:aws:ecs:us-east-1:435433059373:task/jenkins-build-cluster/ba7c88b826114baa8b7e864a0fe3faa3
2019-06-11 14:03:29.885+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: TaskDefinitionArn: arn:aws:ecs:us-east-1:435433059373:task-definition/jenkins-build-cluster-jenkins-ecs-worker:4
2019-06-11 14:03:29.885+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: ClusterArn: arn:aws:ecs:us-east-1:435433059373:cluster/jenkins-build-cluster
2019-06-11 14:03:29.885+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: ContainerInstanceArn: null
2019-06-11 14:03:30.008+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: Waiting for agent to start
2019-06-11 14:03:31.121+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: Waiting for agent to start
...
2019-06-11 14:05:01.481+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: Waiting for agent to start
2019-06-11 14:05:02.598+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: Waiting for agent to start
2019-06-11 14:05:03.711+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: Waiting for agent to start
2019-06-11 14:05:04.816+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: Waiting for agent to start
2019-06-11 14:05:06.087+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: Task started, waiting for agent to become online
2019-06-11 14:05:06.087+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: Waiting for agent to connect
2019-06-11 14:05:07.087+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: Waiting for agent to connect
2019-06-11 14:06:07.107+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: Waiting for agent to connect

... (~50 lines deleted)

2019-06-11 14:06:08.108+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: Waiting for agent to connect
2019-06-11 14:06:08.165+0000 [id=32324]	WARNING	h.TcpSlaveAgentListener$ConnectionHandler#run: Connection #39 failed
java.io.EOFException
	at java.io.DataInputStream.readFully(DataInputStream.java:197)
	at java.io.DataInputStream.readUTF(DataInputStream.java:609)
	at java.io.DataInputStream.readUTF(DataInputStream.java:564)
	at hudson.TcpSlaveAgentListener$ConnectionHandler.run(TcpSlaveAgentListener.java:264)
2019-06-11 14:06:09.108+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: Waiting for agent to connect
2019-06-11 14:06:10.108+0000 [id=32033]	INFO	c.c.j.p.amazonecs.ECSLauncher#launch: [jenkins-build-cluster-pbxr1]: Waiting for agent to connect

... repeats until timeout

Details from the running Fargate task look like this:

Command | ["-url","https://10.0.3.51:50000/","4c2e4a0152369e721e6dba9854c039506c558a380c012e370fe433f83d524bf7","jenkins-build-cluster-m3wrm"]
-- | --
Privileged: false
Network bindings - not configured

Network mode is awsvpc and the subnet matches the Jenkins server.

I don't see any errors or anything else that's obviously wrong, but maybe experts here will. Thanks for any help on this.

Pass dynamic environment variable

Hello,
Is it possible to send custom environment variable to the task definition? Say I have a jenkins pipeline which is trying to provision a slave and I wan to pass the build_url to the docker container as env variable. It doesn't work if I set a new env variable as $BUILD_URL or System.getEnv("BUILD_URL").

Best practice of running docker build

It seems Docker-in-Docker is only option to make docker build workings with this plugin, but still need lots of setting to make sure the build work correctly, just curious about if anyone has any best practice/advice can be shared?

Speedup ECS slave provisioning / do not wait for available executor

I've been using this plugin for 2 years now, and I still have this issue, and it's even been reported as 'getting worse' by my colleagues. I'm probably missing something here.

Let me explain.

Let's say I have one job running, in a slave named 'ecs-slave-1234' provisioned by ECS plugin, based on the Label 'slave'. (Label in the sens of ECS plugin configuration, and 'node' in the sense of the pipeline)

Then I trigger another job, with the same node('slave')

In the job's console I see

Waiting for next available executor on ‘ecs-slave-1234’

Then it ... waits ... as if it anted to reuse the provisioned one, even if it should be a disposable slave.

In jenkins logs it ends up with logs below (with origin slaves name, slightly different than in my explanation here)

Is there a way to tell Jenkins never to reuse an existing executor ?

It sometimes waits up to 3 minutes beofre deciding it sould provision something. A real pain.

I'm using Jenkins LTS 2.176.1
ECS Plugin 1.20

Thank you !

Jul 16, 2019 10:42:41 AM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: Asked to provision 1 agent(s) for: jenkins-slave
Jul 16, 2019 10:42:41 AM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: In provisioning : []
Jul 16, 2019 10:42:41 AM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: Excess workload after pending ECS agents: 1
Jul 16, 2019 10:42:41 AM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: Will provision ECS Agent jenkins-slave, for label: jenkins-slave
Jul 16, 2019 10:42:41 AM hudson.slaves.NodeProvisioner$StandardStrategyImpl apply
INFO: Started provisioning ECS Agent jenkins-slave from factory-slaves with 1 executors. Remaining excess workload: -0.289
Jul 16, 2019 10:42:51 AM hudson.slaves.NodeProvisioner$2 run
INFO: ECS Agent jenkins-slave provisioning successfully completed. We have now 3 computer(s)```

Support to define tags

ECS supports defining tags for tasks. Like other settings from taskdefinition, the plugin should allow the configuration of tags as well.

Note, tags can only be used after opt-in to the new Amazon Resource Name (ARN) and resource identifier (ID) formats.

Slave is not getting registered

Seeing the following error while registering the slave in Jenkins. I have tried using "Tunnel connection through" but error changed to Server didn't accept the handshake: HTTP/1.1 400 Illegal character CNTL=0x0
Could you please help me to debug (FYI slaves are working when I am using EC2 agent plugin to register slaves as EC2 instance).

Warning: JnlpProtocol3 is disabled by default, use JNLP_PROTOCOL_OPTS to alter the behavior
Nov 30, 2019 4:22:40 AM hudson.remoting.jnlp.Main createEngine
INFO: Setting up agent: slave-6tplx
Nov 30, 2019 4:22:40 AM hudson.remoting.jnlp.Main$CuiListener <init>
INFO: Jenkins agent is running in headless mode.
Nov 30, 2019 4:22:41 AM hudson.remoting.Engine startEngine
INFO: Using Remoting version: 3.35
Nov 30, 2019 4:22:41 AM hudson.remoting.Engine startEngine
WARNING: No Working Directory. Using the legacy JAR Cache location: /home/jenkins/.jenkins/cache/jars
Nov 30, 2019 4:22:41 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Locating server among [http://jenkins-sbox.us-east-1.elb.amazonaws.com/]
Nov 30, 2019 4:22:41 AM org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver resolve
INFO: Remoting server accepts the following protocols: [JNLP4-connect, Ping]
Nov 30, 2019 4:22:41 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Agent discovery successful
  Agent address: jenkins-sbox.us-east-1.elb.amazonaws.com
  Agent port:    50000
  Identity:      7d:6d:e3:05:c9:57:27:35:50:5d:9b:e5:91:2c:08:db
Nov 30, 2019 4:22:41 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Handshaking
Nov 30, 2019 4:22:41 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Connecting to jenkins-sbox.us-east-1.elb.amazonaws.com:50000
Nov 30, 2019 4:22:41 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Trying protocol: JNLP4-connect
Nov 30, 2019 4:22:41 AM org.jenkinsci.remoting.protocol.impl.AckFilterLayer abort
WARNING: [JNLP4-connect connection to jenkins-sbox.us-east-1.elb.amazonaws.com/10.5.4.23:50000] Incorrect acknowledgement sequence, expected 0x000341434b got 0x485454502f
Nov 30, 2019 4:22:41 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Protocol JNLP4-connect encountered an unexpected exception
java.util.concurrent.ExecutionException: org.jenkinsci.remoting.protocol.impl.ConnectionRefusalException: Connection closed before acknowledgement sent
	at org.jenkinsci.remoting.util.SettableFuture.get(SettableFuture.java:223)
	at hudson.remoting.Engine.innerRun(Engine.java:577)
	at hudson.remoting.Engine.run(Engine.java:488)
Caused by: org.jenkinsci.remoting.protocol.impl.ConnectionRefusalException: Connection closed before acknowledgement sent
	at org.jenkinsci.remoting.protocol.impl.AckFilterLayer.onRecvClosed(AckFilterLayer.java:280)
	at org.jenkinsci.remoting.protocol.FilterLayer.abort(FilterLayer.java:164)
	at org.jenkinsci.remoting.protocol.impl.AckFilterLayer.abort(AckFilterLayer.java:130)
	at org.jenkinsci.remoting.protocol.impl.AckFilterLayer.onRecv(AckFilterLayer.java:258)
	at org.jenkinsci.remoting.protocol.ProtocolStack$Ptr.onRecv(ProtocolStack.java:668)
	at org.jenkinsci.remoting.protocol.impl.AgentProtocolClientFilterLayer.onRecv(AgentProtocolClientFilterLayer.java:81)
	at org.jenkinsci.remoting.protocol.ProtocolStack$Ptr.onRecv(ProtocolStack.java:668)
	at org.jenkinsci.remoting.protocol.NetworkLayer.onRead(NetworkLayer.java:136)
	at org.jenkinsci.remoting.protocol.impl.BIONetworkLayer.access$2200(BIONetworkLayer.java:48)
	at org.jenkinsci.remoting.protocol.impl.BIONetworkLayer$Reader.run(BIONetworkLayer.java:283)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:97)
	at java.lang.Thread.run(Thread.java:748)
Nov 30, 2019 4:22:41 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Connecting to jenkins-sbox.us-east-1.elb.amazonaws.com:50000
Nov 30, 2019 4:22:41 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Server reports protocol JNLP4-plaintext not supported, skipping
Nov 30, 2019 4:22:41 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Protocol JNLP3-connect is not enabled, skipping
Nov 30, 2019 4:22:41 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Server reports protocol JNLP2-connect not supported, skipping
Nov 30, 2019 4:22:41 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Server reports protocol JNLP-connect not supported, skipping
Nov 30, 2019 4:22:41 AM hudson.remoting.jnlp.Main$CuiListener error
SEVERE: The server rejected the connection: None of the protocols were accepted
java.lang.Exception: The server rejected the connection: None of the protocols were accepted
	at hudson.remoting.Engine.onConnectionRejected(Engine.java:662)
	at hudson.remoting.Engine.innerRun(Engine.java:602)
	at hudson.remoting.Engine.run(Engine.java:488)

Declarative pipeline Fargate example does not work (Invalid agent type "ecs" specified.)

When I run a simple declarative pipeline like the one in your PR comments and your readme, I am hit with this error immediately when trying to create a Fargate agent:

Invalid agent type "ecs" specified. Must be one of [any, docker, dockerfile, label, none]

There is no "agent type" called "ecs" as far as Jenkins is able to determine, and we've even tried to restart the instance itself with hopes that maybe the plugin needed another reload before it could be detected and run properly in a pipeline.

The code we are trying is this example provided by this project, modified a bit to strip out any additional complications:

pipeline {
  agent none

  stages {
    stage('Test') {
        agent {
            ecs {
                inheritFrom 'jnlp-slave'
                cpu 2048
                memory 4096
            }
        }
        steps {
            sh 'echo hello'
        }
    }
  }
}

Can this documentation get some clarification? This is the only example we can find regarding using this in a declarative pipeline, so we have absolutely no idea what to change here to get this working.

Question/Feature Request: Full configuration as code

Hi team

I noticed that your plugin does not currently support the configuration-as-code plugin.

Looking at your README.md and at your ECSDeclarativeAgent.java class, I had the impression that this may not even be required, but I was hoping you could help me out.

What I would like to achieve is to configure the build agents cloud 100% scripted. Currently the configuration-as-code plugin is my go-to approach, falling back to groovy on the exception.

Do you have any samples where you configure your build agents as code, instead of manually entering the configuration in the Jenkins web console?

Thanks, I appreciate any help given!

Declarative Pipeline Not Working

Hi,

I really liked this plugin and I ran a few tests and it worked pretty well. But I'm trying now to run a pipeline and I can't manage to make it work.
I always receive this error:

Started by user Admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] ecsTaskTemplate
[Pipeline] // ecsTaskTemplate
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
ERROR: Cloud does not exist: cloud-default
Finished: FAILURE

The pipeline that I'm trying to run is:

pipeline {
  agent none

  stages {
    stage('Test') {
        agent {
            ecs {
                inheritFrom 'ecs-label'
            }
        }
        steps {
            sh 'echo hello'
        }
    }
  }
}

I also tried to add: "cloud 'ecs'", but didn't work:

        agent {
            ecs {
                cloud 'ecs'
                inheritFrom 'ecs-label'
            }
        }

And the error was the same, just changed the name of the cloud:
ERROR: Cloud does not exist: ecs

My configuration is this:
Error

Could you guys help me?

taskDefinitionOverride ignored while cleaning up the resources

Hi guys! I'm trying to run fargate agent, and because of the issue 95 I've set up template using my custom task definition. However, I encountered another error - plugin seems to not know that task definition was overrided and it still tries to remove non-existant generic task definition.

[Pipeline] Start of Pipeline
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] ecsTaskTemplate
[Pipeline] {
[Pipeline] node
Still waiting to schedule task
‘ecs-cloud-jenkins-jq429’ is offline
Running on ecs-cloud-jenkins-jq429 in /home/jenkins/workspace/jenkins-test
[Pipeline] {
[Pipeline] sh

  • echo hello
    hello
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] }
    [Pipeline] // ecsTaskTemplate
    [Pipeline] }
    [Pipeline] // stage
    [Pipeline] End of Pipeline

GitHub has been notified of this commit’s build result

java.lang.NullPointerException
at com.cloudbees.jenkins.plugins.amazonecs.ECSService.removeTemplate(ECSService.java:298)
at com.cloudbees.jenkins.plugins.amazonecs.ECSCloud.removeDynamicTemplate(ECSCloud.java:353)
at com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution$ECSTaskTemplateCallback.finished(ECSTaskTemplateStepExecution.java:185)
at org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback$TailCall.onSuccess(BodyExecutionCallback.java:118)
at org.jenkinsci.plugins.workflow.cps.CpsBodyExecution$SuccessAdapter.receive(CpsBodyExecution.java:377)
at com.cloudbees.groovy.cps.Outcome.resumeFrom(Outcome.java:73)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:166)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:347)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:93)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:259)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:247)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

In Jenkins logs:
May 20, 2019 10:04:35 PM com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSDeclarativeAgent getAsArgs
INFO: In getAsArgs. label: jenkins-test-36-xsskl
May 20, 2019 10:04:35 PM com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSDeclarativeAgent getAsArgs
INFO: In getAsArgs. argMap: {assignPublicIp=false, cpu=1024, inheritFrom=base-template, label=jenkins-test-36-xsskl, name=jenkins-test-36-xsskl, overrides=[cpu, inheritFrom, label], privileged=false}
May 20, 2019 10:04:35 PM com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution start
INFO: Registering task template with name jenkins-test-36-xsskl-62wj9
May 20, 2019 10:04:45 PM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: Asked to provision 1 agent(s) for: jenkins-test-36-xsskl
May 20, 2019 10:04:45 PM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: In provisioning : []
May 20, 2019 10:04:45 PM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: Excess workload after pending ECS agents: 1
May 20, 2019 10:04:45 PM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: Will provision ECS Agent jenkins-test-36-xsskl, for label: jenkins-test-36-xsskl
May 20, 2019 10:04:45 PM hudson.slaves.NodeProvisioner$StandardStrategyImpl apply
INFO: Started provisioning ECS Agent jenkins-test-36-xsskl from ecs-cloud-jenkins with 1 executors. Remaining excess workload: 0
May 20, 2019 10:04:55 PM hudson.slaves.NodeProvisioner$2 run
INFO: ECS Agent jenkins-test-36-xsskl provisioning successfully completed. We have now 2 computer(s)
May 20, 2019 10:04:55 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher runECSTask
INFO: [ecs-cloud-jenkins-t5lv9]: Starting agent with task definition arn:aws:ecs:region:xxxxxxxxxxxx:task-definition/jenkins-agent:7}
May 20, 2019 10:04:56 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher runECSTask
INFO: [ecs-cloud-jenkins-t5lv9]: Agent started with task arn : arn:aws:ecs:region:xxxxxxxxxxxx:task/fb86408c-4d22-4c3b-b47c-286e74b8207b
May 20, 2019 10:04:56 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher launch
INFO: [ecs-cloud-jenkins-t5lv9]: TaskArn: arn:aws:ecs:region:xxxxxxxxxxxx:task/fb86408c-4d22-4c3b-b47c-286e74b8207b
May 20, 2019 10:04:56 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher launch
INFO: [ecs-cloud-jenkins-t5lv9]: TaskDefinitionArn: arn:aws:ecs:region:xxxxxxxxxxxx:task-definition/jenkins-agent:7
May 20, 2019 10:04:56 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher launch
INFO: [ecs-cloud-jenkins-t5lv9]: ClusterArn: arn:aws:ecs:region:xxxxxxxxxxxx:cluster/jenkins-clu
...
May 20, 2019 10:06:24 PM com.cloudbees.jenkins.plugins.amazonecs.ECSSlave _terminate
INFO: [ecs-cloud-jenkins-t5lv9]: Stopping: TaskArn arn:aws:ecs:region:xxxxxxxxxxxx:task/fb86408c-4d22-4c3b-b47c-286e74b8207b, ClusterArn arn:aws:ecs:region:xxxxxxxxxxxx:cluster/jenkins-clu
May 20, 2019 10:06:24 PM com.cloudbees.jenkins.plugins.amazonecs.ECSService stopTask
INFO: Delete ECS agent task: arn:aws:ecs:region:xxxxxxxxxxxx:task/fb86408c-4d22-4c3b-b47c-286e74b8207b
May 20, 2019 10:06:24 PM com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution$ECSTaskTemplateCallback finished
INFO: Removing task template jenkins-test-36-xsskl-62wj9 from cloud ecs-cloud-jenkins
May 20, 2019 10:06:24 PM com.cloudbees.jenkins.plugins.amazonecs.ECSService findTaskDefinition
INFO: No existing task definition found for family or ARN: ecs-cloud-jenkins-jenkins-test-36-xsskl-62wj9
May 20, 2019 10:06:24 PM jenkins.slaves.DefaultJnlpSlaveReceiver channelClosed
WARNING: Computer.threadPoolForRemoting [#110] for ecs-cloud-jenkins-t5lv9 terminated
java.nio.channels.ClosedChannelException
at org.jenkinsci.remoting.protocol.impl.ChannelApplicationLayer.onReadClosed(ChannelApplicationLayer.java:209)
at org.jenkinsci.remoting.protocol.ApplicationLayer.onRecvClosed(ApplicationLayer.java:222)
at org.jenkinsci.remoting.protocol.ProtocolStack$Ptr.onRecvClosed(ProtocolStack.java:816)
at org.jenkinsci.remoting.protocol.FilterLayer.onRecvClosed(FilterLayer.java:287)
at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.onRecvClosed(SSLEngineFilterLayer.java:181)
at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.switchToNoSecure(SSLEngineFilterLayer.java:283)
at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.processWrite(SSLEngineFilterLayer.java:503)
at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.processQueuedWrites(SSLEngineFilterLayer.java:248)
at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.doSend(SSLEngineFilterLayer.java:200)
at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.doCloseSend(SSLEngineFilterLayer.java:213)
at org.jenkinsci.remoting.protocol.ProtocolStack$Ptr.doCloseSend(ProtocolStack.java:784)
at org.jenkinsci.remoting.protocol.ApplicationLayer.doCloseWrite(ApplicationLayer.java:173)
at org.jenkinsci.remoting.protocol.impl.ChannelApplicationLayer$ByteBufferCommandTransport.closeWrite(ChannelApplicationLayer.java:314)
at hudson.remoting.Channel.close(Channel.java:1452)
at hudson.remoting.Channel.close(Channel.java:1405)
at hudson.slaves.SlaveComputer.closeChannel(SlaveComputer.java:832)
at hudson.slaves.SlaveComputer.kill(SlaveComputer.java:799)
at hudson.model.AbstractCIBase.killComputer(AbstractCIBase.java:88)
at hudson.model.AbstractCIBase.updateComputerList(AbstractCIBase.java:227)
at jenkins.model.Jenkins.updateComputerList(Jenkins.java:1581)
at jenkins.model.Nodes$6.run(Nodes.java:261)
at hudson.model.Queue._withLock(Queue.java:1381)
at hudson.model.Queue.withLock(Queue.java:1258)
at jenkins.model.Nodes.removeNode(Nodes.java:252)
at jenkins.model.Jenkins.removeNode(Jenkins.java:2096)
at hudson.slaves.AbstractCloudSlave.terminate(AbstractCloudSlave.java:70)
at org.jenkinsci.plugins.durabletask.executors.OnceRetentionStrategy$1$1.run(OnceRetentionStrategy.java:128)
at hudson.model.Queue._withLock(Queue.java:1381)
at hudson.model.Queue.withLock(Queue.java:1258)
at org.jenkinsci.plugins.durabletask.executors.OnceRetentionStrategy$1.run(OnceRetentionStrategy.java:123)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

May 20, 2019 10:06:25 PM org.jenkinsci.plugins.workflow.job.WorkflowRun finish
INFO: my-repo/my-project #36 completed: FAILURE

Can't configure plugin with Jenkins 1.625.3

Steps to reproduce,

Jenkins 1.625.3 should be ok based on https://wiki.jenkins.io/display/JENKINS/Amazon+EC2+Container+Service+Plugin

  1. Install plugin
  2. Goto configuration page
  3. Add ECS cloud
  4. Add credentials
  5. No way to select them, dropdown is empty and log as provided below
[WARNING] Error while serving http://localhost:8080/jenkins/descriptorByName/com.cloudbees.jenkins.plugins.amazonecs.ECSCloud/fillClusterItems
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:298)
	at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:161)
	at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:96)
	at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:121)
	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
	at org.kohsuke.stapler.MetaClass$6.doDispatch(MetaClass.java:249)
	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:649)
	at org.kohsuke.stapler.Stapler.service(Stapler.java:238)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1650)
	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:132)
	at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:123)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:49)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:84)
	at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:76)
	at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:171)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:49)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:81)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at org.kohsuke.stapler.DiagnosticThreadNameFilter.doFilter(DiagnosticThreadNameFilter.java:30)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1629)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:190)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:219)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.Server.handle(Server.java:564)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:317)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
	at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
	at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:199)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodError: jenkins.model.Jenkins.get()Ljenkins/model/Jenkins;
	at com.cloudbees.jenkins.plugins.amazonecs.ECSService.getAmazonECSClient(ECSService.java:95)
	at com.cloudbees.jenkins.plugins.amazonecs.ECSCloud$DescriptorImpl.doFillClusterItems(ECSCloud.java:384)
	... 65 more

using ssh slaves instead of jnlp slaves

For our use case, the master is not accessible from the internet, so we need to launch agents via ssh as opposed to jnlp. However, I don't see any way of setting this. Is this feature missing?

Support "Usage" parameter for default builds on ECS

Hi, I have a use-case where if i don't provide any label, my builds execute on the master, but instead, i want the builds to be executed by default on ECS slaves. I've seen in some cloud plugins there is this Usage parameter (attached) that has two options:

  1. Use this node as much as possible (aka Mode: NORMAL)
  2. Only build jobs with label expressions matching this node. (aka Mode: EXCLUSIVE)

I believe this plugin works only with option 2, but Is there any way to use option 1 so that my builds don't, by default, execute on the master but rather on ECS slaves? Is this even possible?

Thanks!

aws-ecs-jenkinscli

And thank you for creating a really nice plugin :)

Issue mounting docker.sock in ECS

Hello,

I'm trying to figure out how to mount docker.sock to the ECS Jenkins agent so that I can spawn other containers for specific build steps. I am having trouble getting it to work properly.

My latest attempt:

pipeline {
    agent {
        ecs {
            cloud 'qa-east-agent-cloud'
            label 'qa-east-agent'
            memory 1024
            image 'ninech/jnlp-slave-with-docker'
            mountPoints([
                [
                    name: 'docker_socket', 
                    sourcePath:'unix:///var/run/docker.sock', 
                    containerPath:'unix:///var/run/docker.sock',
                    readOnly: false
                ]
            ])
        }
    }
...

I'm not sure if this is the correct syntax as it's not documented anywhere, this is my best attempt I could derive from the code (as I am not an experienced Java developer).

I'm noticing in the logs that these override variables may not actually be applied:

2019-12-06 21:30:02.146+0000 [id=1528]	INFO	c.c.j.p.a.p.ECSDeclarativeAgent#getAsArgs: In getAsArgs. argMap: {assignPublicIp=false, cloud=qa-east-agent-cloud, image=ninech/jnlp-slave-with-docker, label=qa-east-agent, memory=1024, name=qa-east-agent, overrides=[cloud, image, label, memory, mountPoints], privileged=false}

Then below:

2019-12-06 21:30:18.600+0000 [id=1450]	INFO	c.c.j.p.amazonecs.ECSService#registerTemplate: Created Task Definition: {TaskDefinitionArn: arn:aws:ecs:us-east-1:618804428340:task-definition/qa-east-agent-cloud-qa-east-agent-q9tn0:1,ContainerDefinitions: [{Name: qa-east-agent-cloud-qa-east-agent-q9tn0,Image: ninech/jnlp-slave-with-docker,Cpu: 0,Memory: 1024,Links: [],PortMappings: [],Essential: true,EntryPoint: [],Command: [],Environment: [],MountPoints: [],VolumesFrom: [],Secrets: [],DependsOn: [],Privileged: false,DnsServers: [],DnsSearchDomains: [],ExtraHosts: [],DockerSecurityOptions: [],Ulimits: [],SystemControls: [],ResourceRequirements: [],}],Family: qa-east-agent-cloud-qa-east-agent-q9tn0,Revision: 1,Volumes: [],Status: ACTIVE,RequiresAttributes: [],PlacementConstraints: [],Compatibilities: [EC2],RequiresCompatibilities: [],InferenceAccelerators: [],}

Specifically, MountPoints: []. Confirmed that this is also an empty list in the resulting task definition.

I noticed in this pull request (#13) this use case is specifically referenced in the comments, but I am having trouble finding examples.

Can anyone point me in the right direction?

Thanks.

Could not find matching constructor for ECSTaskTemplate

Hi, I upgraded my Jenkins to 2.164 from really an old version. After upgrade my bootstrap scripts failed, which I was able to fix after looking at few examples over the internet. The ECSTaskTemplate spec is still not what we have in the interface, not it complies with class definition in the source code. Now I need to provide TaskExecutionRole and when I try to change the ECSTaskTemplate construction, it returns below exception.

groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate

My Groovy part for ECSTaskTemplate is as below.

ecsTemplates << new ECSTaskTemplate(
//templateName=ecsTemplate.name,
ecsTemplate.name,
//label=ecsTemplate.label,
ecsTemplate.label,
//taskDefinitionOverride='',
null,
//image=ecsTemplate.image,
ecsTemplate.image,
//repositoryCredentials=null,
null,
//launchType="EC2",
"FARGATE",
//networkMode="default",
"awsvpc",
//remoteFSRoot="/home/jenkins",
"/home/jenkins",
//memory=1024,
4096,
//memoryReservation=2048,
0,
//cpu=1,
1024,
//subnets=null,
"subnet-77b4d800",
//securityGroups=null,
"sg-03e9a2d31478e7b5a",
//assignPublicIp=false,
false,
//DNS Search Domains
null,
//Task Role ARN
null,
//Task Execution Role ARN
"arn:aws:iam::224093794013:role/res-transformation-jenkins",
//Override Entrypoint
null,
//JVM Arguments
null,
//privileged=false,
false,
//containerUser=null,
null,
//Log Driver
null,
//logDriverOptions=logDriverOptions,
logDriverOptions,
//environments=environments,
environments,
//extraHosts=extraHosts,
extraHosts,
//mountPoints=mountPoints,
null,
//portMappings=null
null
)

Slave not able to connect to master

I went through setup as you specified in the readme in the project but when I kick off a build I am getting connection refused on port 50000. The error message below:

Nov 22, 2019 7:53:23 PM hudson.remoting.jnlp.Main$CuiListener error
SEVERE: Failed to connect to jenkins-elb-293478233.us-east-1.elb.amazonaws.com:50000
java.io.IOException: Failed to connect to jenkins-elb-293478233.us-east-1.elb.amazonaws.com:50000
at org.jenkinsci.remoting.engine.JnlpAgentEndpoint.open(JnlpAgentEndpoint.java:242)
at hudson.remoting.Engine.connectTcp(Engine.java:678)
at hudson.remoting.Engine.innerRun(Engine.java:556)
at hudson.remoting.Engine.run(Engine.java:488)
Caused by: java.net.ConnectException: Connection refused
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Net.java:454)
at sun.nio.ch.Net.connect(Net.java:446)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648)
at java.nio.channels.SocketChannel.open(SocketChannel.java:189)
at org.jenkinsci.remoting.engine.JnlpAgentEndpoint.open(JnlpAgentEndpoint.java:203)
... 3 more

I have both load balancer and ec2 sg allowing port 50000. Is there something I am doing wrong here? I even exposed 50000 in the Dockerfile for master.

[Doc] Jenkins wiki sunset

Currently the readme forwards users to the Jenkins wiki page. However, the Jenkins wiki has been converted to read-only mode and is pushing for a migration to documentation-as-code (see both the big red warning on the top of the wiki page and this posting). Ideally, the documentation from the wiki should be moved to the readme.

Does ECS plugin support agents connecting directly to tcp port?

https://github.com/jenkinsci/remoting/blob/master/docs/tcpAgent.md#connect-directly-to-tcp-port

Here is the command in one of my ECS task detail:

Command | ["-url","http://jenkins-master-alb-1874758640.us-east-1.elb.amazonaws.com:8080/","-tunnel","Jenkins-Master-NLB-1a610ec726b19db5.elb.us-east-1.amazonaws.com:50000","c13783e0173a5a3d21c464aed5be0c45811c5afae08712c24cebb7a786d899ee","ecs-cloud-lnx-r67b0"]

Here is the command for connecting directly to tcp port.

Command | ["-direct","Jenkins-Master-NLB-1a610ec726b19db5.elb.us-east-1.amazonaws.com:50000","-instanceIdentity","$JENKINS_INSTANCE_IDENTITY","$JENKINS_SECRET","$JENKINS_AGENT_NAME"]

Here is the script I used for agent image entrypoint.
https://github.com/jenkinsci/docker-jnlp-slave/blob/master/jenkins-agent

If it is supported, how to do it in the plugin settings or in ecs task definition? Thanks.

Declarative pipelines don't work with any overrides

I am using the version of the plugin 1.23 with Jenkins 2.176.2. I have a cloud associated with a template and the plugin starts ECS agents correctly when called with an agent { label 'ecs-label'} and also from a freestyle project with using the same label and restrictions. Then I am trying a very simple declarative pipeline:

pipeline {
    agent {
        ecs {
            inheritFrom 'ecs-label'
        }
    }

  stages {
    stage('Test') {
        steps {
            sh 'echo hello'
        }
    }
  }
}

Which results in the error message

ERROR: Not allowed to override inheritFrom. Allowed overrides are 
Finished: FAILURE

The peculiar part is that this worked correctly with version 1.22 until I created a second cloud in a different region and I have not managed to run an agent { ecs { } } block with any configuration since.
I have tried reinstalling the plugin. I upgrade to the latest version - 1.22 - deleted all the clouds and recreated them all resulting in the same error.
I used to get a list of supported allowed overrides, at the moment I only get an empty string for allowed overrides.

Support "Hot" Slaves or Standby Pool

I'd like to have a pool of nodes ready to start jobs rather than provisioning one-at-a-time. I'm wondering if an API could be created to register nodes and pass back JNLP tokens. If that was possible, I could then create an ECS "Service" with a pool of nodes ready to start jobs.

To some degree this seems possible:
https://support.cloudbees.com/hc/en-us/articles/115003896171-Creating-node-with-the-REST-API

I looked into doing this myself, but I don't understand the internals of Jenkins well enough to create an API. Although I did manage to write some groovy to create nodes from within Jenkins.

Other resources:
https://stackoverflow.com/questions/42683324/create-jenkins-jlnp-slave-programmatically

Support Parallel ECS agent spawning

When using a parallel within a pipeline I would like to use the ECS plugin to spawn agents. The problem is that when I make the request out to spawn multiple ECS agents they spawn one at a time. It seems the the ECS plugin can only spawn one agent until that agent comes online fully. Which means they spawn in a potentially random order even though the cloud provisioner knows that all the agents are of the ECS type.

It would be great if the ECS plugin would support the multithreaded approach to spawning agents like EC2 or docker cloud plugins.

I am not sure of the AWS APIs support such a thing but it would be a great feature to have.

Declarative agent cpu/memory override causes "Container.image should not be null or empty"

We have an existing template called ecs-nodejs that defaults memory/cpu to 2048/2048. That has been working fine using:

pipeline {
  agent { label "ecs-nodejs" }
  // ...
}

We're looking to override it for a particular build using the following pipeline:

pipeline {
  agent { 
    ecs {
      inheritFrom "ecs-nodejs"
      cpu 8192
      memory 4096
    }
  }
  // ...
}

When that is run, the build never starts and we get the following message in logs:

Jul 02, 2019 9:49:14 PM INFO com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSDeclarativeAgent getAsArgs
In getAsArgs. label: master-25-61z9s
Jul 02, 2019 9:49:14 PM INFO com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSDeclarativeAgent getAsArgs
In getAsArgs. argMap: {assignPublicIp=false, cpu=8192, inheritFrom=ecs-nodejs, label=master-25-61z9s, memory=4096, name=master-25-61z9s, overrides=[cpu, inheritFrom, memory, label], privileged=false}
Jul 02, 2019 9:49:14 PM INFO com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution start
Registering task template with name master-25-61z9s-dhc47
Jul 02, 2019 9:49:20 PM INFO com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
Asked to provision 1 agent(s) for: master-25-61z9s
Jul 02, 2019 9:49:20 PM INFO com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
In provisioning : []
Jul 02, 2019 9:49:20 PM INFO com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
Excess workload after pending ECS agents: 1
Jul 02, 2019 9:49:20 PM INFO com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
Will provision ECS Agent master-25-61z9s, for label: master-25-61z9s
Jul 02, 2019 9:49:20 PM INFO hudson.slaves.NodeProvisioner$StandardStrategyImpl apply
Started provisioning ECS Agent master-25-61z9s from ecs-cloud with 1 executors. Remaining excess workload: 0
Jul 02, 2019 9:49:30 PM INFO hudson.slaves.NodeProvisioner$2 run
ECS Agent master-25-61z9s provisioning successfully completed. We have now 4 computer(s)
Jul 02, 2019 9:49:30 PM INFO com.cloudbees.jenkins.plugins.amazonecs.ECSService findTaskDefinition
No existing task definition found for family or ARN: ecs-cloud-master-25-61z9s-dhc47
Jul 02, 2019 9:49:30 PM WARNING com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher launch
[ecs-cloud-s4zpx]: Error in provisioning; agent=com.cloudbees.jenkins.plugins.amazonecs.ECSSlave[ecs-cloud-s4zpx]
com.amazonaws.services.ecs.model.ClientException: Container.image should not be null or empty. (Service: AmazonECS; Status Code: 400; Error Code: ClientException; Request ID: c7ce24a5-090b-470d-b0ae-006ff4876bf6)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1712)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1367)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1113)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:770)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:744)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:726)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:686)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:668)
	at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:532)
	at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:512)
	at com.amazonaws.services.ecs.AmazonECSClient.doInvoke(AmazonECSClient.java:3839)
	at com.amazonaws.services.ecs.AmazonECSClient.invoke(AmazonECSClient.java:3806)
	at com.amazonaws.services.ecs.AmazonECSClient.invoke(AmazonECSClient.java:3795)
	at com.amazonaws.services.ecs.AmazonECSClient.executeRegisterTaskDefinition(AmazonECSClient.java:2666)
	at com.amazonaws.services.ecs.AmazonECSClient.registerTaskDefinition(AmazonECSClient.java:2636)
	at com.cloudbees.jenkins.plugins.amazonecs.ECSService.registerTemplate(ECSService.java:286)
	at com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher.getTaskDefinition(ECSLauncher.java:201)
	at com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher.launch(ECSLauncher.java:107)
	at hudson.slaves.SlaveComputer$1.call(SlaveComputer.java:294)
	at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
	at jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:71)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)```

The plugin doesn't scale

Hi

Infrastructure:
I created the ECS cluster for slave agents with Auto Scaling based on CPU value.
The initial instance was taken with 2 Cores and 4 Ram, where for build task I configured to consume 1 CPU and 2GB Ram per build
Therefore, I would imagine that 2 agents can be spawned per instance and whenever 2nd agent will kick off the build, the CPU value for AutoScailing will go above the threshold and new instance will be spawned, what would allow deploying more agents to ECS.

Jenkins Project
I configured the plugin, point to the ECS cluster described above and used the base Docker image (btw look at: #110 ) with 1024 per CPU and 2048 RAM as already described above

I created 2 dummy projects with parallel builds allowed and with a single build step sleep for 5 min
After I executed 3 builds per each project = 6 builds in total pending in the Q

Expected
The plugin will start spawning as many agents as possible to accommodate all builds in the Q, to accommodate parallel builds.
And infrastructure behind ECS cluster will scale automatically based on the CPU load (it base AWS AutoScale functionality, outside of this plugin context)

Actual Result
Only 1 agent was spawned, where rest of the build tasks remains in the Q waiting for that single agent instead of spawning new agents for parallel execution

What did I configure wrong?

Amazon ECS Plugin using AWS Externalid

Hi Team,

We are using Amazon EC2 Container Service Plugin and we are successfully able to spin up Conatiners as Slaves in AWS.
https://github.com/jenkinsci/amazon-ecs-plugin

Plugin details : https://wiki.jenkins-ci.org/display/JENKINS/Amazon+EC2+Container+Service+Plugin

we have multiple Projects and we require multiple Amazon Ec2 container service cloud . As of now we have created multiple Ec2 container service clouds but
we have observed there is no restrictions for binding/restricting the agents on the Folder.

Cansome one help/suggest how to use AWS externalid to achieve this . We have got references from below
https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user_externalid.html .
We wanted to restirct Jenkins Project Folder using AWS external id .Appreciate if some one helps with Request for enhancement.

thankyou,
Prashanth K.

Declarative Override Fail - 1.20-beta2

Which version are you using? The declarative support comes with 1.20 with is currently in beta (1.20-beta2)

Please, could help us?
We install 1.20-beta2 but we are not having success in the declarative override:

pipeline {
agent any
stages {
stage('Test') {
agent {
ecs {
cloud 'cloud-default'
label 'ecs'
image 'jenkinsci/jnlp-slave'
launchType 'FARGATE'
memory 4096
cpu 2048
subnets 'subnet-xxxxxxxxxxxxx'
securityGroups 'sg-xxxxxxxxxxx'
assignPublicIp true
taskrole 'arn:aws:iam::xxxxxxxxxxxxxxx:role/ecsTaskExecutionRole'
inheritFrom 'fargate-template'
}
}
steps {
sh 'echo hello'
}
}
}
}

Jenkins output:
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] ecsTaskTemplate
[Pipeline] // ecsTaskTemplate
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Cloud does not exist: cloud-default
Finished: FAILURE

Jenkins Log:
Apr 11, 2019 9:13:08 PM INFO com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSDeclarativeAgent getAsArgs
In getAsArgs. label: ecs
Apr 11, 2019 9:13:08 PM INFO com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSDeclarativeAgent getAsArgs
In getAsArgs. argMap: {assignPublicIp=true, cloud=cloud-default, cpu=2048, image=jenkinsci/jnlp-slave, inheritFrom=fargate-template, label=ecs, launchType=FARGATE, memory=4096, name=ecs, overrides=[assignPublicIp, cloud, cpu, image, inheritFrom, label, launchType, memory, securityGroups, subnets, taskrole], privileged=false, securityGroups=sg-xxxxxxxx, subnets=subnet-xxxxxxxx, taskrole=arn:aws:iam::xxxxxxxx:role/ecsTaskExecutionRole}
Apr 11, 2019 9:13:08 PM INFO org.jenkinsci.plugins.workflow.job.WorkflowRun finish
test_pipeline #36 completed: FAILURE

Originally posted by @alineprattiezops in #84 (comment)

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate$LogDriverOption

Hi, I am using groovy init and bootstrap scripts to configure my Jenkins. After startup, it seems Jenkins is not reading the ECSTemplate properly. However, if I go to Jenkins Configuration again (Manage Jenkins -> Configuration), and just save it again, without changing anything, it starts working, I mean it starts provisioning the Agents.

I get below error/exception in my logs before saving the config again.

INFO: ECS Agent base-agent linux provisioning successfully completed. We have now 3 computer(s)
Mar 29, 2019 11:43:46 AM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher launch
WARNING: [linux-gd6pf]: Error in provisioning; agent=com.cloudbees.jenkins.plugins.amazonecs.ECSSlave[linux-gd6pf]
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate$LogDriverOption
at com.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate.getLogDriverOptionsMap(ECSTaskTemplate.java:473)
at com.cloudbees.jenkins.plugins.amazonecs.ECSService.registerTemplate(ECSService.java:209)
at com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher.getTaskDefinition(ECSLauncher.java:200)
at com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher.launch(ECSLauncher.java:106)
at hudson.slaves.SlaveComputer$1.call(SlaveComputer.java:294)
at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
at jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:71)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Support swarm slaves

I would like to use this plugin in conjunction with the swarm plugin, but I'm seeing some difficulties.

Rationale: Swarm slaves make it much easier to configure things like tool locations than the normal JNLP slaves, because you can pass this info on the command line to the swarm jar. Also, I already have a jenkins slave container that uses the swarm client, and it would make sense to use the same image across the ECS slaves and any other kind of slave.

Problem I'm seeing: I've managed to tweak the image to get it to be compatible with how this plugin launches the containers, so it does actually launch. However, this plugin registers a new slave before launching the container. This prevents the swarm slave from starting correctly, because it believes that the slave already exists. Swarm can be configured to delete the pre-existing slave if it has the same name, but that confuses the ECS plugin, because the slave it just created disappears, meaning it tries to register a new one (and it just continues round in the loop).

It's not obvious from looking at the code how to change this behaviour. It looks like the creation and deletion of the slaves is all part of the CloudSlave functionality in core jenkins - removing the creation without removing the deletion (which is still required) may be difficult?

[Doc] example mentioned but missing in readme

per the readme:

Declarative agents can be defined like shown below. You can also reuse pre-configured templates and override certain settings using inheritFrom to reference the Label field of the template that you want to use as preconfigured. Only one label is expected to be specified.

however, there's no example shown of configuration without using pre-configured templates and inheritFrom.

taskDefinitionOverride Not working as expected.

Hi,
I am trying to use this plugin to run ECS agents with as little configuration on the jenkins side as possible, ie very little config in the jenkinsfile and no ECS Agent Templates. I can get it to work sort of...

However I find I must always declare inheritFrom in my jenkinsfile, or else my build fails once they are completed as they cannot do 'removeDynamicTemplate'. Looking at the code I see

is the issue.
It is saying to find a template override it must have a value from inheritFrom. This makes sense only to write a nice log, I removed this and changed it to check the value of getTaskDefinitionOverride() and it works perfectly for my use case. Am I doing something wrong or should I make PR to fix this? Thanks 🙂

Jenkins is not creating task definition for Fargate

After doing some round of testing, I realized that Jenkins is not creating Fargate task definition automatically using this plugin. If I pass already created Task definition ARN in Task Definition Override, it works fine & spins up Fargate slaves.

For managed EC2 run(old-ECS), it is successfully creating task definition & running it on cluster.

image

[BUG] Declarative pipeline overriding Fargate definition doesn't work

Overriding attributes from an inherited template works when creating dynamic agents via Declarative pipeline ONLY when the original template uses EC2 as launch mode.

So this WORKS:

agent {
       ecs {
                inheritFrom 'ec2-template'
                cpu 1024
                memory 4096
            }
    }

this DOES NOT WORK:

agent {
       ecs {
                inheritFrom 'fargate-template'
                cpu 1024
                memory 4096
            }
    }

Here are the relevant logs for a task inherited from fargate-template:

Dec 19, 2019 11:28:52 AM INFO com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSDeclarativeAgent getAsArgs
In getAsArgs. label: ecs-agent-test-10-zl3f1
Dec 19, 2019 11:28:52 AM INFO com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSDeclarativeAgent getAsArgs
In getAsArgs. argMap: {assignPublicIp=false, cpu=1024, inheritFrom=fargate-template, label=ecs-agent-test-10-zl3f1, memory=8192, name=ecs-agent-test-10-zl3f1, overrides=[cpu, inheritFrom, memory, label], privileged=false}
Dec 19, 2019 11:28:52 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStep
In ECSTaskTemplateStep start. label: ecs-agent-test-10-zl3f1
Dec 19, 2019 11:28:52 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStep
In ECSTaskTemplateStep start. cloud: cloud-default
Dec 19, 2019 11:28:52 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution
In ECSTaskTemplateExecution run()
Dec 19, 2019 11:28:52 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution
cloud: cloud-default
Dec 19, 2019 11:28:52 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution
label: ecs-agent-test-10-zl3f1
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] ecsTaskTemplate
[Pipeline] // ecsTaskTemplate
[Pipeline] End of Pipeline
ERROR: Cloud does not exist: cloud-default
Finished: FAILURE

And here's what happens when I run the exact same thing but inheriting from ec2-template:

Dec 19, 2019 11:31:46 AM INFO com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSDeclarativeAgent getAsArgs
In getAsArgs. label: ecs-agent-test-11-krf00
Dec 19, 2019 11:31:46 AM INFO com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSDeclarativeAgent getAsArgs
In getAsArgs. argMap: {assignPublicIp=false, cpu=1024, inheritFrom=ec2-template, label=ecs-agent-test-11-krf00, memory=8192, name=ecs-agent-test-11-krf00, overrides=[cpu, inheritFrom, memory, label], privileged=false}
Dec 19, 2019 11:31:46 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStep
In ECSTaskTemplateStep start. label: ecs-agent-test-11-krf00
Dec 19, 2019 11:31:46 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStep
In ECSTaskTemplateStep start. cloud: cloud-default
Dec 19, 2019 11:31:46 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution
In ECSTaskTemplateExecution run()
Dec 19, 2019 11:31:46 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution
cloud: cloud-default
Dec 19, 2019 11:31:46 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution
label: ecs-agent-test-11-krf00
Dec 19, 2019 11:31:46 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution
Cloud maxCpu: 0
Dec 19, 2019 11:31:46 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution
Cloud maxMemory: 0
Dec 19, 2019 11:31:46 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution
Cloud maxMemoryReservation: 0
Dec 19, 2019 11:31:46 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution
Step cpu: 1,024
Dec 19, 2019 11:31:46 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution
Step memory: 8,192
Dec 19, 2019 11:31:46 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution
Step memoryReservation: 0
Dec 19, 2019 11:31:46 AM FINE com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution
Step shareMemorySize: 0
Dec 19, 2019 11:31:46 AM INFO com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSTaskTemplateStepExecution start
Registering task template with name ecs-agent-test-11-krf00-88vps
Dec 19, 2019 11:31:48 AM INFO com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
Asked to provision 1 agent(s) for: ecs-agent-test-11-krf00
Dec 19, 2019 11:31:48 AM INFO com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
In provisioning : []
Dec 19, 2019 11:31:48 AM INFO com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
Excess workload after pending ECS agents: 1
Dec 19, 2019 11:31:48 AM INFO com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
Will provision ECS Agent ecs-agent-test-11-krf00, for label: ecs-agent-test-11-krf00
Dec 19, 2019 11:31:58 AM FINE com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher
ECS: Launching agent
Dec 19, 2019 11:31:58 AM FINE com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher
[Dev-cluster-wsvqv]: Creating Task in cluster null
Dec 19, 2019 11:31:58 AM FINE com.cloudbees.jenkins.plugins.amazonecs.ECSCloud
Selected Region: us-east-1
Dec 19, 2019 11:31:58 AM FINE com.cloudbees.jenkins.plugins.amazonecs.ECSCloud
Selected Region: us-east-1
Dec 19, 2019 11:31:58 AM FINE com.cloudbees.jenkins.plugins.amazonecs.ECSCloud
No existing task definition found for family or ARN: Dev-cluster-ecs-agent-test-11-krf00-88vps
[..]
[.. Task succesfully completes at the end. I've truncated output as it's not super relevant anymore ..]

I have thus far:

  • Allowed all overrides in the settings
  • Confirmed that this DOES NOT happen to ANY task that is inheriting from an EC2 launch type templates
  • Confirmed that specifying cloud doesn't change anything.
  • Confirmed that NOT specifying cloud for an ec2 based template doesn't break anything (at least on my setup with just a single cloud)
  • Made sure that the templates themselves work, if we don't involve any overriding.

It feels to me that the issue lies here -


That for some reason the Fargate based templates do not return as provisonable, but I don't have the environment setup to actually do any development or testing this.

P.S.
A similar issue was described in #116, abut then closed without a proper resolution.

Declarative Agent Declaration Doesn't Allow Using Fargate

When using the declarative agent declaration to define or extend an agent with the Fargate launch type, the plugin fails to register the Task Definition with an error that states:

[jenkins-60gn8]: Error in provisioning; agent=com.cloudbees.jenkins.plugins.amazonecs.ECSSlave[jenkins-60gn8]
com.amazonaws.services.ecs.model.ClientException: Fargate requires task definition to have execution role ARN to support ECR images. (Service: AmazonECS; Status Code: 400; Error Code: ClientException; Request ID: eb36ec6a-6c41-11e9-ae73-89fda2289aa7)

Upon doing some digging, it looks like com.cloudbees.jenkins.plugins.amazonecs.pipeline.ECSDeclarativeAgent does not have a property for executionRole but com.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate does. I believe this is leading to the execution role not being passed in the RegisterTaskDefinition call.

ECS Clusters Past 100 Not Listed

It looks like it was supposed to be fixed but I'm running 1.21 and still seeing issues where only 100 clusters for ECS are showing up so I can't get to my ECS cluster to pick for my node/job setup.

Can we confirmation on if this was truly fixed? What info do you need from me for this issue?

Many jobs starting at the same time exceeds task definition rate limit and holds it there

If to many tasks start in a short time (as on a busy jenkins) then this plugin starts hitting the rate limit on task definition creation. Once it's in that state it retries many times and no tasks ever start.
It constantly get's the error:

com.amazonaws.services.ecs.model.ClientException: Too many concurrent attempts to create a new revision of the specified family. (Service: AmazonECS; Status Code: 400; Error Code: ClientException; Request ID: bb3cafd7-97b2-11e9-9e00-5ff346cf8ee8)

A workaround to get past this is to specify the Task Definition Override option to the name of the most recently created task definition. This stops this plugin from generating new task definitions and get's past this error.

One idea for a proper fix would be a weighted random back off when this exception is caught.

     com.amazonaws.services.ecs.model.ClientException: Too many concurrent attempts to create a new revision of the specified family. (Service: AmazonECS; Status Code: 400; Error Code: ClientException; Request ID: bb3cNNNNN8ee8)
             at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1695)
             at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1350)
             at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1101)
             at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:758)
             at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:732)
             at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:714)
             at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:674)
             at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:656)
             at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:520)
             at com.amazonaws.services.ecs.AmazonECSClient.doInvoke(AmazonECSClient.java:3265)
             at com.amazonaws.services.ecs.AmazonECSClient.invoke(AmazonECSClient.java:3232)
             at com.amazonaws.services.ecs.AmazonECSClient.invoke(AmazonECSClient.java:3221)
             at com.amazonaws.services.ecs.AmazonECSClient.executeRegisterTaskDefinition(AmazonECSClient.java:2284)
             at com.amazonaws.services.ecs.AmazonECSClient.registerTaskDefinition(AmazonECSClient.java:2255)
             at com.cloudbees.jenkins.plugins.amazonecs.ECSService.registerTemplate(ECSService.java:285)
             at com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher.getTaskDefinition(ECSLauncher.java:200)
             at com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher.launch(ECSLauncher.java:106)
             at hudson.slaves.SlaveComputer$1.call(SlaveComputer.java:294)
             at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
             at jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:71)
             at java.util.concurrent.FutureTask.run(FutureTask.java:266)
             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
             at java.lang.Thread.run(Thread.java:748)

Plugin is not able to run Task in ECS EC2 unless save configuration thru console

Jenkins is not able to run a task in ECS EC2 until unless I save or apply configuration thru console. We are launching Jenkins thru JCasC v1.27 and using Amazon Elastic Container Service plugin v1.22 (amazon-ecs) and throwing below exception in logs.

Logs before Apply configurations thru Console:

Aug 22, 2019 10:27:28 AM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: Asked to provision 1 agent(s) for: Linux
Aug 22, 2019 10:27:28 AM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: In provisioning : []
Aug 22, 2019 10:27:28 AM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: Excess workload after pending ECS agents: 1
Aug 22, 2019 10:27:28 AM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: Will provision ECS Agent Linux, for label: Linux
Aug 22, 2019 10:27:28 AM hudson.slaves.NodeProvisioner$StandardStrategyImpl apply
INFO: Started provisioning ECS Agent Linux from V2-Pipeline with 1 executors. Remaining excess workload: 0
Aug 22, 2019 10:27:38 AM hudson.slaves.NodeProvisioner$2 run
INFO: ECS Agent Linux provisioning successfully completed. We have now 4 computer(s)
Aug 22, 2019 10:27:38 AM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: Asked to provision 1 agent(s) for: Linux
Aug 22, 2019 10:27:38 AM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: In provisioning : [V2-Pipeline-f9rnw]
Aug 22, 2019 10:27:38 AM com.cloudbees.jenkins.plugins.amazonecs.ECSCloud provision
INFO: Excess workload after pending ECS agents: 0
Aug 22, 2019 10:27:39 AM com.cloudbees.jenkins.plugins.amazonecs.ECSService registerTemplate
INFO: Match on container definition: true
Aug 22, 2019 10:27:39 AM com.cloudbees.jenkins.plugins.amazonecs.ECSService registerTemplate
INFO: Match on volumes: true
Aug 22, 2019 10:27:39 AM com.cloudbees.jenkins.plugins.amazonecs.ECSService registerTemplate
INFO: Match on task role: true
Aug 22, 2019 10:27:39 AM com.cloudbees.jenkins.plugins.amazonecs.ECSService registerTemplate
INFO: Match on execution role: true
Aug 22, 2019 10:27:39 AM com.cloudbees.jenkins.plugins.amazonecs.ECSService registerTemplate
INFO: Match on network mode: true
Aug 22, 2019 10:27:39 AM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher runECSTask
INFO: [V2-Pipeline-f9rnw]: Starting agent with task definition arn:aws:ecs:us-west-2:*******:task-definition/V2-Pipeline-npe-v2-pipeline:1}
Aug 22, 2019 10:27:39 AM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher launch
WARNING: [V2-Pipeline-f9rnw]: Error in provisioning; agent=com.cloudbees.jenkins.plugins.amazonecs.ECSSlave[V2-Pipeline-f9rnw]
com.amazonaws.services.ecs.model.InvalidParameterException: Override argument cannot be null. (Service: AmazonECS; Status Code: 400; Error Code: InvalidParameterException; Request ID: 4a9d3be7-3cbf-4859-935e-51d54ed7133d)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1712)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1367)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1113)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:770)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:744)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:726)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:686)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:668)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:532)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:512)
at com.amazonaws.services.ecs.AmazonECSClient.doInvoke(AmazonECSClient.java:3934)
at com.amazonaws.services.ecs.AmazonECSClient.invoke(AmazonECSClient.java:3901)
at com.amazonaws.services.ecs.AmazonECSClient.invoke(AmazonECSClient.java:3890)
at com.amazonaws.services.ecs.AmazonECSClient.executeRunTask(AmazonECSClient.java:2795)
at com.amazonaws.services.ecs.AmazonECSClient.runTask(AmazonECSClient.java:2766)
at com.cloudbees.jenkins.plugins.amazonecs.ECSService.runEcsTask(ECSService.java:358)
at com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher.runECSTask(ECSLauncher.java:221)
at com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher.launch(ECSLauncher.java:109)
at hudson.slaves.SlaveComputer$1.call(SlaveComputer.java:294)
at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
at jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:71)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Logs after Apply configurations thru Console:

Aug 22, 2019 12:17:18 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher runECSTask
INFO: [V2-Pipeline-qq35v]: Starting agent with task definition arn:aws:ecs:us-west-2::task-definition/V2-Pipeline-npe-v2-pipeline:1}
Aug 22, 2019 12:17:18 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher runECSTask
INFO: [V2-Pipeline-qq35v]: Agent started with task arn : arn:aws:ecs:us-west-2:
:task/aa3854e0-0d9e-4d48-a4c6-856da9368f66
Aug 22, 2019 12:17:18 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher launch
INFO: [V2-Pipeline-qq35v]: TaskArn: arn:aws:ecs:us-west-2::task/aa3854e0-0d9e-4d48-a4c6-856da9368f66
Aug 22, 2019 12:17:18 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher launch
INFO: [V2-Pipeline-qq35v]: TaskDefinitionArn: arn:aws:ecs:us-west-2:
:task-definition/V2-Pipeline-npe-v2-pipeline:1
Aug 22, 2019 12:17:18 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher launch
INFO: [V2-Pipeline-qq35v]: ClusterArn: arn:aws:ecs:us-west-2::cluster/npe-v2-pipeline
Aug 22, 2019 12:17:18 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher launch
INFO: [V2-Pipeline-qq35v]: ContainerInstanceArn: arn:aws:ecs:us-west-2:
:container-instance/8e75e7be-0f0a-41d0-a926-214f87d430e6
Aug 22, 2019 12:17:18 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher launch
INFO: [V2-Pipeline-qq35v]: Waiting for agent to start
Aug 22, 2019 12:17:19 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher launch
INFO: [V2-Pipeline-qq35v]: Waiting for agent to start
Aug 22, 2019 12:17:35 PM com.cloudbees.jenkins.plugins.amazonecs.ECSLauncher launch
INFO: [V2-Pipeline-qq35v]: Agent connected
Aug 22, 2019 12:17:35 PM com.cloudbees.jenkins.plugins.amazonecs.ECSComputer taskAccepted
INFO: [V2-Pipeline-qq35v]: JobName: part of testp_monolith » build-pipeline » test-monolith » v2pipeline_testbranch_3 #16
Aug 22, 2019 12:17:35 PM com.cloudbees.jenkins.plugins.amazonecs.ECSComputer taskAccepted

Can someone please take a look and advice.

thanks,
Satish
ecs-plugin-config-2
ecs-plugin-config-1

Fargate and Declarative Pipeline issue

Currently trying to use the plug in to connect to a AWS Fargate server to sping up a Docker Container Slave and Jenkins will not log in to a Cloud no matter what. It will constantly output ERROR: Cloud does not exist: cloud-default

Using Jenkins Ver 2.176.1.
Amazon EC2 Container Service Plug-in Ver 1.20

Log outputs:
[Pipeline] }

[Pipeline] // withEnv

[Pipeline] End of Pipeline

[Bitbucket] Notifying commit build result

[Bitbucket] Build result notified

ERROR: Cloud does not exist: cloud-default

Finished: FAILURE

Failed on stage:
stage('SSH Slave Test') {
agent {
ecs {
inheritFrom '<>'
}
}
steps {
sh 'echo hello'
}
}

Feature request: Support for multiple labels

It would be nice to assign multiple labels to an ECS agent template instead of just the one. The use case for this is that I have ECS agents that have the same image but are running in either a different VPC or AWS account. So I would like my Jenkinsfile script to support

agent {
    label 'java8 && aws-account:some-team && vpc:qa'
}

I would also like to request that a label parameter be added to the cloud configuration so that it can be inherited by the ecs agent templates. That way I don't have to repeat the label on each ecs agent template that are part of the same ECS cluster/cloud.

Allowing multiple labels allows jobs to be more flexible or more precise in choosing slaves to execute on.

Feature request: Support Capacity Providers

Amazon recently made Fargate Spot generally available. What it basically does is run Fargate tasks in an EC2 Spot Instance-esque fashion, while greatly reducing the cost to run them.
This seems like a match made in heaven for running certain Jenkins jobs at an extremely attractive price.

What we'd need to do is support the specification of Capacity Providers when defining Cloud Provider Templates. That could look similar to Placement Strategies field in the current implementation.

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/fargate-capacity-providers.html

Support shm-size Docker option

Hi,

I've hit this issue trying to do end to end testing with firefox and geckodriver where the browser just crashes because it hit the shm size limit defaulted to 64mb in Docker. When setting this higher, everything works again.

The problem, of course, is that this plugin doesn't support that option currently which would make my life infinitely easier. I'm sure I'm not the only one that's had this issue.

Cheers.

Feature request: Assume role for API calls

Hi,

I have a use case where I would like to deploy ECS agents in account B, from my jenkins master in account A. While leaving out credentials will use account A's role accurately, the plugin is not able to assume a role in account B without supplying the credentials to Jenkins.

It would be nice if a role ARN can be specified for the plugin's AWS client, which is then used for all actions, as a step after the initial authorization:

  1. Get AWS API access using credentials if specified, otherwise automatically use role
  2. If an assume role ARN is specified, assume this role to do further API actions.

What do you think of this addition?

How to share docker cache across slaves

Hi,

our build images jobs are taking too much time to download resources from internet/intranet(so cannot use even mirror registry).

We are looking at sharing cache so that we can save some time during docker builds.

After looking at multiple pages i understand we cannot share /var/lib/docker folder is there any way to share the docker cache?

Thanks in advance.

Plugin doesn't always clean up old nodes in Jenkins, even though the containers are stopped in ECS

We've run in to this issue a few times recently since setting this up where multiple disconnected nodes will be listed in Jenkins, and builds will try to run on these nodes even though the ECS plugin has spun up a new container. When these nodes are deleted, builds will resume again. I've cleared it up this last time it happened, but let me know what kind of logs or info you need to troubleshoot this and I'll collect it next time it happens.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.