Jenkins Autoscaler is a tool that automatically adjusts the size of the Jenkins worker nodes in AWS or GCP when one of the following conditions is true:
- If the usage of Jenkins nodes is smaller then the specified threshold, it will scale down or if the usage is larger then a specified threshold, will scale up to the maximum of specified size limit.
- Running garbage collector to remove zombie nodes.
- When the queue is empty, it checks whether any node can be terminated by establishing whether the node is in idle state.
- One node is kept running all the time, apart during non working hours.
- Once a node is online, it's kept alive for at least 20 minutes.
Jenkins Autoscaler utilizes Amazon EC2 Auto Scaling Groups to manage node groups.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DescribeAutoScalingInstances",
"autoscaling:DescribeScalingActivities",
"autoscaling:SetDesiredCapacity",
"autoscaling:TerminateInstanceInAutoScalingGroup",
"ec2:DescribeInstances"
],
"Resource": ["*"]
}
]
}
https://www.googleapis.com/auth/compute
https://www.googleapis.com/auth/cloud-platform
make install
jas --help # to see all options
example how to run in gce
jas \
--backend=gce \
--gce-project=my-gce-project \
--gce-region=us-east1 \
--gce-instance-group-manager=my-jenkins-instance-group \
--jenkins-url=https://ci.jenkins.com \
--jenkins-user=jenkins-admin \
--jenkins-token=jenkins6user6token6here
example how to run in aws
jas \
--backend=aws \
--aws-region=us-east-1 \
--aws-autoscaling-group-name=my-jenkins-asg \
--jenkins-url=https://ci.jenkins.com \
--jenkins-user=jenkins-admin \
--jenkins-token=jenkins6user6token6here
example how to run with the config file
scaler:
log_level: debug
dry_run: true
run_interval: 3s
gc_run_interval: 3s
scale_up_grace_period: 5m
scale_down_grace_period: 10m
scale_down_grace_period_during_working_hours: 1h
controller_node_name: Built-In Node
scale_up_threshold: 70
scale_down_threshold: 30
max_nodes: 10
min_nodes_during_working_hours: 2
jenkins_url: https://my.jenkins.co
jenkins_user: ""
jenkins_token: ""
backend:
gce:
project: gcp-project
region: us-east1
instance_group_manager: jenkins-nodes
aws:
autoscaling_group_name: jenkins-nodes
region: us-east-1
# run with configuration file
jas --backend=gce -c ./configs/my-jenkins-autoscaler.yaml
Feel free to open Pull-Request for small fixes and changes. For bigger changes and new backends please open an issue first to prevent double work and discuss relevant stuff.
Licensed under the MIT License. See the LICENSE file for details.