mirror of https://github.com/k3s-io/k3s
99 lines
4.6 KiB
Plaintext
99 lines
4.6 KiB
Plaintext
|
pipeline {
|
||
|
agent any
|
||
|
environment {
|
||
|
setupResultsOut = "setup-results.xml"
|
||
|
testResultsOut = "results.xml"
|
||
|
|
||
|
AWS_ACCESS_KEY_ID = credentials('AWS_ACCESS_KEY_ID')
|
||
|
AWS_SECRET_ACCESS_KEY = credentials('AWS_SECRET_ACCESS_KEY')
|
||
|
AWS_SSH_PEM_KEY = credentials('AWS_SSH_PEM_KEY')
|
||
|
}
|
||
|
|
||
|
stages {
|
||
|
stage('Git Checkout') {
|
||
|
steps {
|
||
|
git branch: 'add_automation_using_tf', url: 'https://github.com/ShylajaDevadiga/k3s.git'
|
||
|
script {
|
||
|
dir("${WORKSPACE}/tests/terraform") {
|
||
|
if (env.AWS_SSH_PEM_KEY && env.AWS_SSH_KEY_NAME) {
|
||
|
def decoded = new String(AWS_SSH_PEM_KEY.decodeBase64())
|
||
|
writeFile file: AWS_SSH_KEY_NAME, text: decoded
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
stage('Configure') {
|
||
|
steps {
|
||
|
sh """
|
||
|
set -e -x
|
||
|
echo 'aws_ami="${env.AWS_AMI}"
|
||
|
aws_user="${env.AWS_USER}"
|
||
|
region="${env.REGION}"
|
||
|
vpc_id="${env.VPC_ID}"
|
||
|
subnets="${env.SUBNETS}"
|
||
|
qa_space="${env.QA_SPACE}"
|
||
|
ec2_instance_class="${env.EC2_INSTANCE_CLASS}"
|
||
|
access_key="/config/$AWS_SSH_KEY_NAME"
|
||
|
no_of_worker_nodes="${env.NO_OF_WORKER_NODES}"
|
||
|
key_name="jenkins-rke-validation"
|
||
|
server_flags="${env.SERVER_FLAGS}"
|
||
|
worker_flags="${env.WORKER_FLAGS}"
|
||
|
k3s_version="${env.K3S_VERSION}"
|
||
|
availability_zone="${env.AVAILABILITY_ZONE}"
|
||
|
sg_id="${env.SG_ID}"
|
||
|
install_mode="${env.INSTALL_MODE}"
|
||
|
resource_name="${env.RESOURCE_NAME}"
|
||
|
no_of_server_nodes="${env.NO_OF_SERVER_NODES}"
|
||
|
username="${env.RHEL_USERNAME}"
|
||
|
password="${env.RHEL_PASSWORD}"
|
||
|
db_username="${env.DB_USERNAME}"
|
||
|
db_password="${env.DB_PASSWORD}"
|
||
|
node_os="${env.NODE_OS}"
|
||
|
environment="${env.ENVIRONMENT}"
|
||
|
engine_mode="${env.ENGINE_MODE}"
|
||
|
external_db="${env.EXTERNAL_DB}"
|
||
|
external_db_version="${env.EXTERNAL_DB_VERSION}"
|
||
|
instance_class="${env.DB_INSTANCE_CLASS}"
|
||
|
db_group_name="${env.DB_GROUP_NAME}"
|
||
|
cluster_type="${env.CLUSTER_TYPE}"
|
||
|
create_lb=${env.CREATE_LB}
|
||
|
' >${WORKSPACE}/tests/terraform/${env.NODE_OS}${env.EXTERNAL_DB}".tfvars"
|
||
|
"""
|
||
|
}
|
||
|
}
|
||
|
stage('Build Cluster') {
|
||
|
steps {
|
||
|
sh """
|
||
|
|
||
|
/usr/bin/docker build -f tests/terraform/Dockerfile.build -t k3s_create_cluster .
|
||
|
|
||
|
/usr/bin/docker run -d --name ${RESOURCE_NAME}_${BUILD_NUMBER} -v ${WORKSPACE}/tests/terraform:/config \
|
||
|
-t -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
|
||
|
k3s_create_cluster
|
||
|
|
||
|
/usr/bin/docker cp "${WORKSPACE}/tests/terraform/${NODE_OS}${EXTERNAL_DB}".tfvars "${RESOURCE_NAME}_${BUILD_NUMBER}":/config
|
||
|
|
||
|
/usr/bin/docker cp "${WORKSPACE}/tests/terraform/$AWS_SSH_KEY_NAME" "${RESOURCE_NAME}_${BUILD_NUMBER}":/config
|
||
|
|
||
|
/usr/bin/docker exec ${RESOURCE_NAME}_${BUILD_NUMBER} /usr/local/go/bin/go test -v tests/terraform/createcluster.go \
|
||
|
tests/terraform/createcluster_test.go tests/terraform/testutils.go -v \
|
||
|
-timeout=2h -node_os=${NODE_OS} \
|
||
|
-cluster_type=${CLUSTER_TYPE} -external_db=${EXTERNAL_DB} -resource_name=${RESOURCE_NAME} \
|
||
|
-sshuser=${AWS_USER} -sshkey="/config/${AWS_SSH_KEY_NAME}" -destroy=false -arch=${ARCH}
|
||
|
|
||
|
"""
|
||
|
}
|
||
|
}
|
||
|
|
||
|
stage('Test Report') {
|
||
|
steps {
|
||
|
sh """
|
||
|
/usr/bin/docker rm -f ${RESOURCE_NAME}_${BUILD_NUMBER}
|
||
|
/usr/bin/docker rmi -f k3s_create_cluster
|
||
|
"""
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|