Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroy instance after completing a certain number of builds #23

Open
major opened this issue Apr 1, 2020 · 3 comments
Open

Destroy instance after completing a certain number of builds #23

major opened this issue Apr 1, 2020 · 3 comments

Comments

@major
Copy link

major commented Apr 1, 2020

I would like a feature in the ec2 spot fleet plugin that would allow me to specify a maximum number of builds on an instance before it is destroyed. This exists in the regular EC2 Jenkins plugin, but it does not exist in the EC2 spot fleet plugin.

In short, I would like to say:

  • Destroy an instance when it has been idle for X minutes (this exists today)
  • Destroy an instance when it has processed 100 builds (whether it is idle or not) (this does not exist today)
@terma
Copy link
Contributor

terma commented Apr 1, 2020

Just wondering what is use case behind destroying after some build numbers?

@major
Copy link
Author

major commented Apr 1, 2020

@terma Our team has a need for instances in EC2 that we only want to run one time (because we alter system configuration and install packages inside the instance). We also find that we end up with a mess in /tmp or other directories after lots of jobs run, so it would be nice to stop the instance after a certain number of builds as well.

If there's a better way to destroy our running instance when the job is done, that would work for me, too.

@lloydchang
Copy link

Hi, @major; Cc: @terma

Here's a workaround to add into your Jenkins job's Build: Execute shell:

#!/bin/bash -x

if [ "${BUILD_NUMBER}" -ge "100" ]; then
  INSTANCE_ID=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)
  aws ec2 terminate-instances --instance-ids ${INSTANCE_ID}
fi

for

• Destroy an instance when it has processed 100 builds (whether it is idle or not) (this does not exist today)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants