<p>What you are looking for is called <strong>dynamic provisioning</strong> of Jenkins' slaves, and yes this is doable. Setting it up depends upon your desired infrastructure provider/resource. The easiest example in my opinion is using AWS EC2 instances. Install the <a href="https://wiki.jenkins.io/display/JENKINS/Amazon+EC2+Plugin" rel="nofollow noreferrer">Amazon EC2 Plugin</a> for Jenkins, and configure it with the appropriate access keys, IAM roles, etc. to allow it to provision EC2 instances in a specified VPC. Here is a short (but slightly outdated) <a href="https://www.cakesolutions.net/teamblogs/jenkins-and-on-demand-slaves-in-aws" rel="nofollow noreferrer">guide</a>. </p>

<p>If you are moving to K8's and Docker, you may want to consider looking into the <a href="https://wiki.jenkins.io/display/JENKINS/Docker+Plugin" rel="nofollow noreferrer">Docker Plugin</a> for Jenkins. If you are using bare bones infrastructure, this should allow you to more effectively utilize what current hardware you have. </p>

CC BY-SA 3.0
2018-03-07T14:15:56.237Z
I think you've misunderstood my question; we are already set up to automatically launch slaves. The issue is that the automatic launching is too slow; jenkins will wait too long to spin up new instances. I am looking for a way to launch them on my own schedule to supplement the automatic launches.
Alex
CC BY-SA 3.0
2018-03-07T14:45:02.783Z
If time is your issue, you could dedicate a handful of particular slaves to running unit tests and turn them on when you think the load will be greater than your current nodes can handle. Then turn them off when your job is finished executing. This will give you the quickest turn around time vs having to provision new instances. If the wait is still to long, you may just need to increase the minimum number of continuously running nodes to accommodate the long wait time.
Preston Martin
CC BY-SA 3.0
2018-03-07T14:48:51.057Z
It's a good suggestion but the issue is we need single-use slaves - reusing pollutes our results. It's looking from the answers to this question that there isn't a way to programatically spin up a new agent so I guess we'll just have to deal with the wait until we switch to K8s
Alex
CC BY-SA 3.0
2018-03-07T15:01:19.163Z
You can use the docker plugin to spin up new containers from a docker image that is run the Jenkins agent without using kubernetes. If you truly need them to spin up quickly and need them to be fresh single-use slaves, then this may be your best approach.
Preston Martin
CC BY-SA 3.0
2018-03-06T20:59:24.590Z
2018-03-06T20:59:24.590Z
Preston Martin
<p>We have a jenkins master which has like 10 agents connected via ssh, usually they are down. But when a build starts, jenkins starts an agent automatically(It launches the jar file over ssh).</p>

<p>So I would believe jenkins should solve that problem with the build in logic. If the queue is full it starts up agents which are currently offline.</p>

CC BY-SA 3.0
2018-03-06T14:05:24.087Z
We have our jenkins configured to launch automatically, the issue is the delay. I'd like to supplement the automatic launching with more manual launches.
Alex
CC BY-SA 3.0
2018-03-06T14:51:01.247Z
So what are you looking for ? we used to spin up pre configured VMs on Azure according to need, it is relatively fast since everything is already in place in the VM image.
Rsf
CC BY-SA 3.0
2018-03-06T15:31:22.513Z
I want a command / api call / etc that will let me force-launch a new agent, the same way you can by going to the nodes page and provisioning one manually. The wait-time jenkins has is too long for us; we want a more aggressive provisioning strategy than jenkins' conservative one. It waits too long to see if a previous agent frees up instead of just launching a new one.
Alex
CC BY-SA 3.0
2018-03-05T20:54:43.950Z
2018-03-05T20:54:43.950Z
anstue
<p><strong>Is it possible to launch a jenkins agent from within a script in another job?</strong> I'm open to either shell or pipeline options. </p>

<p>To be clear I don't mean the agent the job is running on itself. I'm talking about spinning up a completely separate agent. </p>

<p>Sometimes our master gets slammed with unit test requests and will make jobs wait in the queue for 15-20+ minutes instead of just spinning up more agents. I want to see if there's a way to spin an agent up intentionally so I can tie it into a job that polls the queue for wait times.</p>

CC BY-SA 3.0
2018-03-05T16:50:18.510Z
Do you have some Jenkins slaves already?
030
CC BY-SA 3.0
2018-03-05T16:56:28.230Z
Yes I do @030 I'm looking to spin up another of a type I already have.
Alex
CC BY-SA 3.0
2018-03-05T20:18:10.700Z
What is your infrastructure? Are you using some cloud solution or is bare metal? I recommend you to test some integration with docker or Kubernetes.
wolmi
CC BY-SA 3.0
2018-03-05T20:20:23.007Z
We're moving to k8 sometime in the next 6 months. I need a quick-fix for our current issue until we can switch over.
Alex
CC BY-SA 3.0
2018-03-05T20:27:47.247Z
In this case take a moment to calculate the cost of automated agent launch vs increase the actual resources for that period (if possible)
wolmi
CC BY-SA 4.0
2021-12-21T15:30:09.890Z
Hi @Alex, did you find a solution without installing a plugin ?
andolsi zied
<jenkins>
Launch jenkins agent from jenkins job?
Alex
# Launch jenkins agent from jenkins job?

(Asked by: username_0 on 2018-03-05)

**Is it possible to launch a jenkins agent from within a script in another job?** I'm open to either shell or pipeline options.

To be clear I don't mean the agent the job is running on itself. I'm talking about spinning up a completely separate agent.

Sometimes our master gets slammed with unit test requests and will make jobs wait in the queue for 15-20+ minutes instead of just spinning up more agents. I want to see if there's a way to spin an agent up intentionally so I can tie it into a job that polls the queue for wait times.

**Tags:** jenkins

> **Comments:**
> **username_1**: Do you have some Jenkins slaves already?  
> **username_0**: Yes I do @username_1 I'm looking to spin up another of a type I already have.  
> **username_2**: What is your infrastructure? Are you using some cloud solution or is bare metal? I recommend you to test some integration with docker or Kubernetes.  
> **username_0**: We're moving to k8 sometime in the next 6 months. I need a quick-fix for our current issue until we can switch over.  
> **username_2**: In this case take a moment to calculate the cost of automated agent launch vs increase the actual resources for that period (if possible)  
> **username_3**: Hi @username_0, did you find a solution without installing a plugin ?  

---

## 2 answers

### Answer by username_4 on 2018-03-06. Score: 1

What you are looking for is called **dynamic provisioning** of Jenkins' slaves, and yes this is doable. Setting it up depends upon your desired infrastructure provider/resource. The easiest example in my opinion is using AWS EC2 instances. Install the [Amazon EC2 Plugin](https://wiki.jenkins.io/display/JENKINS/Amazon+EC2+Plugin) for Jenkins, and configure it with the appropriate access keys, IAM roles, etc. to allow it to provision EC2 instances in a specified VPC. Here is a short (but slightly outdated) [guide](https://www.cakesolutions.net/teamblogs/jenkins-and-on-demand-slaves-in-aws).

If you are moving to K8's and Docker, you may want to consider looking into the [Docker Plugin](https://wiki.jenkins.io/display/JENKINS/Docker+Plugin) for Jenkins. If you are using bare bones infrastructure, this should allow you to more effectively utilize what current hardware you have.

> **Comments:**
> **username_0**: I think you've misunderstood my question; we are already set up to automatically launch slaves. The issue is that the automatic launching is too slow; jenkins will wait too long to spin up new instances. I am looking for a way to launch them on my own schedule to supplement the automatic launches.  
> **username_4**: If time is your issue, you could dedicate a handful of particular slaves to running unit tests and turn them on when you think the load will be greater than your current nodes can handle. Then turn them off when your job is finished executing. This will give you the quickest turn around time vs having to provision new instances. If the wait is still to long, you may just need to increase the minimum number of continuously running nodes to accommodate the long wait time.  
> **username_0**: It's a good suggestion but the issue is we need single-use slaves - reusing pollutes our results. It's looking from the answers to this question that there isn't a way to programatically spin up a new agent so I guess we'll just have to deal with the wait until we switch to K8s  
> **username_4**: You can use the docker plugin to spin up new containers from a docker image that is run the Jenkins agent without using kubernetes. If you truly need them to spin up quickly and need them to be fresh single-use slaves, then this may be your best approach.  

---

### Answer by username_5 on 2018-03-05. Score: 0

We have a jenkins master which has like 10 agents connected via ssh, usually they are down. But when a build starts, jenkins starts an agent automatically(It launches the jar file over ssh).

So I would believe jenkins should solve that problem with the build in logic. If the queue is full it starts up agents which are currently offline.

> **Comments:**
> **username_0**: We have our jenkins configured to launch automatically, the issue is the delay. I'd like to supplement the automatic launching with more manual launches.  
> **username_6**: So what are you looking for ? we used to spin up pre configured VMs on Azure according to need, it is relatively fast since everything is already in place in the VM image.  
> **username_0**: I want a command / api call / etc that will let me force-launch a new agent, the same way you can by going to the nodes page and provisioning one manually. The wait-time jenkins has is too long for us; we want a more aggressive provisioning strategy than jenkins' conservative one. It waits too long to see if a previous agent frees up instead of just launching a new one.  

---

