Appendix: Destroying and recreating a cluster

CloudBees will no longer be supporting CloudBees Jenkins Enterprise 1.x after July 30, 2020. This end-of-life announcement allows CloudBees to focus on driving new technology and product innovation for CloudBees CI. For information on moving to CloudBees CI, please refer to Migrating from CloudBees Jenkins Enterprise 1.x to CloudBees CI on modern cloud platforms which has been created to help you with the migration process. Existing customers can also contact their CSM to help ensure a smooth transition.

This appendix describes how to destroy and recreate a CloudBees Jenkins Enterprise cluster.

Destroy a CloudBees Jenkins Enterprise cluster

When you are finished evaluating CloudBees Jenkins Enterprise or you want to terminate the resources used by a CloudBees Jenkins Enterprise cluster, run the following command:

$ cje prepare cluster-destroy
cluster-destroy is staged - review cluster-destroy.config and edit as needed - then
run `cje apply` to perform the operation.
If bees-pse apply fails, ensure that the machine has valid name servers configured. Running bees-pse apply without a valid name server configuration, or without the host(1) utility installed, will cause the script to fail when resolving addresses.

Edit the cluster-destroy.config file before executing the operation.

Because this is a destructive operation, you must explicitly enter the cluster name in the configuration file. This requirement helps prevent accidental cluster manipulation or destruction.

In the cluster-destroy.config file, available options (operations on clusters and storage buckets, plus — in releases prior to 1.6.0 — operations on Elasticsearch snapshots) are commented out by default.

To invoke any of the three parameters associated with AWS cluster destruction and cleanup (destroying a cluster, storage bucket, or Elasticsearch snapshot), you must first uncomment that parameter in the configuration file by removing the pound sign (#) prefix that by default nullifies the power of these destructive operations by treating them as comments rather than operators.

By uncommenting cluster_name = [your cluster name], destroy_storage_bucket = yes, or destroy_elasticsearch_snapshots = yes, you explicitly permit those operations to be invoked.

{cluster-destroy.config-file} sample excerpt:
[pse]
...
## Cluster name
# Uncomment the next line after verifying that this is really the cluster you want to destroy.
# cluster_name = cobra

(AWS only) You can also decide whether storage buckets should be deleted. The data stored in the storage buckets can be used to recover a cluster after it has been destroyed. However, the data will prevent creating a new cluster of the same name.

Destroying a CloudBees Jenkins Enterprise cluster deletes all the resources associated with that cluster. Depending on the data storage backend used, you may not be able to retrieve data after these resources are deleted.

Destroying all data

Depending on the persistent storage used during installation, data may be left over after destroying the cluster.

rsync

The rsync server and all data is deleted after the cluster is destroyed.

NFS

The NFS directories created for Operations Center and CloudBees Jenkins Enterprise Jenkins masters are not deleted.

AWS Elastic Block Storage

Volumes, snapshots and S3 buckets with Operations Center and CloudBees Jenkins Enterprise Jenkins masters data are not deleted after destroy.

In order to do a full deletion the following script can be used, provided the AWS cli is already configured for the same account used for CloudBees Jenkins Enterprise:

CLUSTER_NAME=myclustername
AWS_REGION=us-east-1

ec2-snapshots-for-cluster() {
    aws ec2 describe-snapshots \
        --region $AWS_REGION \
        --owner-ids self \
        --filters Name=tag:cluster,Values=$CLUSTER_NAME \
        --query 'Snapshots[*].{ID:SnapshotId}' \
        --output text
}

ec2-volumes-for-cluster() {
    aws ec2 describe-volumes \
        --region $AWS_REGION \
        --filters Name=tag:cluster,Values=$CLUSTER_NAME \
        --query 'Volumes[*].{ID:VolumeId}' \
        --output text
}

s3-buckets-for-cluster() {
    for id in $(aws s3api list-buckets --query 'Buckets[].Name' --output text); do
        if [ -n "$CLUSTER_NAME" ] && [ "$CLUSTER_NAME" == "$(aws s3api get-bucket-tagging --bucket $id --query 'TagSet[?Key==`cloudbees:pse:cluster`].Value[]' --output text 2> /dev/null)" ]; then
            echo $id
        fi
    done
}

ec2-volumes-for-cluster | xargs -P 20 -I {} bash -c "echo {}; aws ec2 delete-volume --region $AWS_REGION --volume-id {}"
ec2-snapshots-for-cluster | xargs -P 20 -I {} bash -c "echo {}; aws ec2 delete-snapshot --region $AWS_REGION --snapshot-id {}"
s3-buckets-for-cluster | xargs -P 20 -I {} bash -c "echo {}; aws s3 rb s3://{} --force"
There may be some snapshots and volumes being created for some time after the cluster is destroyed so the command may need to be run again.

Recreating a Destroyed CloudBees Jenkins Enterprise Cluster

The CloudBees Jenkins Enterprise configuration created when you ran cje will not be deleted when you run cje destroy. You can re-initialize by going through the installation process again.