I have a jenkins ubuntu server and several windows nodes running on ec2. I'd like for the server to turn the windows boxes on and off as they're needed. I think that means using the "launch method" in the node config, but I'm not sure what to write.

I currently have Launch Method set to "by connecting it to the master", and have to have a step at the start of my pipeline to call aws ec2 start-instances --instance-ids XXX to start the instance, and the equivalent stop-instances when completing the pipeline, but this means every job turns the machines on and off, even if there's another job queued.

I could maybe put the aws command into the node config, but I only have one command box. I can't put in one command to turn it off and another to turn it on.

Is there a plugin to help here? Or a way to set up the aws call to make this work? Am I even right that launch method is the box I want?


Further to my prior answer regarding basic node configuration options, perhaps the slave-setup plugin offers further manageability.

There is a "pre-launch script" option, which,

"can be used to start the slave machine, before Jenkins tries to ssh it. "

Plugin also offers a "On-demand slave setup": This plugin also provides you a per-slave "start" and "stop" script configuration specific for on-demand slaves. This probably exactly fits your needs.

Once installed, you will have an additional "Launch method" (1) for this case:

this one lets you specify the "Start" (2) and "Stop" (3) scripts, and on top of that you will be able to specify the "conventional" connection (4) method for reaching the slave after it has been started.

You will likely also want to specify that you want this node to be online only when Jenkins needs it (5).

The figure below shows the configuration that you may want to use if your on-demand slave is an Amazon EC2 instance.

AWS setup; from https://wiki.jenkins.io/download/attachments/58002132/68747470733a2f2f676f6c6466697368746970732e66696c65732e776f726470726573732e636f6d2f323031362f30362f746e63686a716e74766a2e706e67.png?version=1&modificationDate=1467444498000&api=v2

  • I've had my node set up like this for a few days and it's been turning on and off successfully.
    – tenpn
    Dec 3 '20 at 9:37

I don't use AWS / ec2, but ... this answer is provided for context to explain some of the options for a node and build on the subsequent accepted answer, which are generally not well documented; pls do not down vote

Have you looked at the option in the node configuration page:


The default Availability is "Keep this agent online as much as possible"

The other options include "Take the agent online when in demand, and offline when idle". This option really does not make much sense unless you have a means to stop/start a VM as it only stops the agent service, not the VM; not clear when this is of more use than just keeping online.

There is an "In demand delay" (The number of minutes for which jobs must have been waiting in the queue before Jenkins will attempt to bring this agent online) and an Idle delay (The number of minutes that this agent must remain idle before Jenkins will take it offline). Even 0 minutes takes a moment to decide to launch or stop.

I'd also adjust the "Usage" to "Only build jobs with label expressions matching this node", label the nodes with a common label (ec2 ?) and then tie your particular stages to the corresponding label, just to control usage better.

If that does not meet your needs, there's the EC2 plugin and guidance provided by AWS on cost optimization for Jenkins.

There are also plugins for AWS Lambda Cloud and AWS CodeBuild Cloud Agents if you're into that.

  • my question specifically mentions the config page you point me to. The options you suggest do nothing unless I can correctly set up the Launch Method field, which was my question. The ec2 plugin is for spinning up new instances - I want to be able to turn on and off the instance I have.
    – tenpn
    Nov 28 '20 at 16:29
  • The whole node configuration piece could do w/better documentation, so some ppl are not aware of the options or what applies to the host server, the jenkins node config or the agent. As I stated, I have not used AWS, but trying to share what I can. Have you investigated the slave-setup plugin, thinking the "pre-launch script" option?
    – Ian W
    Nov 29 '20 at 7:16
  • I've got something that looks like it's working with the slave-setup plugin. want to post it as its own answer and I'll tick it?
    – tenpn
    Nov 30 '20 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.