Skip to content

Commit

Permalink
Added creation of default user for build param placeholder.
Browse files Browse the repository at this point in the history
revert
  • Loading branch information
RobertNorthard authored and Northard, Robert A committed Sep 19, 2016
1 parent cbb5ecd commit 76ae60f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 27 deletions.
23 changes: 23 additions & 0 deletions bootstrap/Platform_Management/Create_default_credentials.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import jenkins.model.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.plugins.credentials.impl.*
import com.cloudbees.jenkins.plugins.sshcredentials.impl.*
import hudson.plugins.sshslaves.*;

def add_username_password_credential(id, username, password, description){
def domain = Domain.global()
def store = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore()

def defaultUsernameAndPassword = new UsernamePasswordCredentialsImpl(
CredentialsScope.GLOBAL,
id,
description,
username,
password
)
store.addCredentials(domain, defaultUsernameAndPassword)
}

add_username_password_credential("adop-default","adop-default", "adop-default","Default credentials for Jenkins. This credential does not grant access to any service." )
50 changes: 27 additions & 23 deletions bootstrap/Platform_Management/Load_Platform_Extension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ def platformManagementFolder = folder(platformManagementFolderName) { displayNam

// Jobs
def loadPlatformExtensionJob = freeStyleJob(platformManagementFolderName + "/Load_Platform_Extension")

// Setup setup_cartridge
loadPlatformExtensionJob.with{
wrappers {
preBuildCleanup()
sshAgent('adop-jenkins-master')
}
parameters{
stringParam("GIT_URL",'',"The URL of the git repo for Platform Extension")
stringParam("GIT_REF","master","The reference to checkout from git repo of Platform Extension. It could be a branch name or a tag name. Eg : master, 0.0.1 etc")
credentialsParam("AWS_CREDENTIALS"){
type('com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl')
description('AWS access key and secret key for your account')
}
stringParam("GIT_URL",'',"The URL of the git repo for Platform Extension")
stringParam("GIT_REF","master","The reference to checkout from git repo of Platform Extension. It could be a branch name or a tag name. Eg : master, 0.0.1 etc")
credentialsParam("CREDENTIALS"){
type('com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl')
defaultValue('adop-default')
description('Platform extension credentials. Note: Leave at adop-default if credentials are not required.')
}
}
scm{
git{
Expand All @@ -35,7 +36,7 @@ loadPlatformExtensionJob.with{
maskPasswords()
sshAgent("adop-jenkins-master")
credentialsBinding {
usernamePassword("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", '${AWS_CREDENTIALS}')
usernamePassword("USERNAME", "PASSWORD", '${CREDENTIALS}')
}
}
steps {
Expand All @@ -50,12 +51,15 @@ fi
# Provision any EC2 instances in the AWS folder
if [ -d ${WORKSPACE}/service/aws ]; then
if [ -f ${WORKSPACE}/service/aws/service.template ]; then
echo "#######################################"
echo "Adding EC2 platform extension on AWS..."
export AWS_ACCESS_KEY_ID=${USERNAME}
export AWS_SECRET_ACCESS_KEY=${PASSWORD}
# Variables
INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
PUBLIC_IP=$(curl http://169.254.169.254/latest/meta-data/public-ipv4)
Expand All @@ -68,10 +72,10 @@ if [ -d ${WORKSPACE}/service/aws ]; then
AWS_VPC_ID=$(aws ec2 describe-instances --instance-ids ${INSTANCE_ID} --query 'Reservations[0].Instances[0].VpcId' --output text);
fi
CIDR_BLOCK=$(aws ec2 describe-vpcs --vpc-ids ${AWS_VPC_ID} --query 'Vpcs[0].CidrBlock' --output text)
ENVIRONMENT_STACK_NAME="${AWS_VPC_ID}-EC2-PLATFORM-EXTENSION-${PLATFORM_EXTENSION_NAME}-${BUILD_NUMBER}"
FULL_ENVIRONMENT_NAME="${AWS_VPC_ID}-EC2-Instance-${PLATFORM_EXTENSION_NAME}-${BUILD_NUMBER}"
aws cloudformation create-stack --stack-name ${ENVIRONMENT_STACK_NAME} \
--tags "Key=createdBy,Value=ADOP-Jenkins" "Key=user,Value=${INITIAL_ADMIN_USER}" \
--template-body file://service/aws/service.template \
Expand All @@ -81,7 +85,7 @@ if [ -d ${WORKSPACE}/service/aws ]; then
ParameterKey=KeyName,ParameterValue=${AWS_KEYPAIR} \
ParameterKey=VPCId,ParameterValue=${AWS_VPC_ID} \
ParameterKey=InboundCIDR,ParameterValue=${CIDR_BLOCK}
# Keep looping whilst the stack is being created
SLEEP_TIME=60
COUNT=0
Expand All @@ -93,7 +97,7 @@ if [ -d ${WORKSPACE}/service/aws ]; then
sleep "${SLEEP_TIME}"
COUNT=$((COUNT+1))
done
# Check that the stack created
TIME_SPENT=$(($COUNT * $SLEEP_TIME))
if $(aws cloudformation describe-stacks --stack-name ${ENVIRONMENT_STACK_NAME} | grep -q "CREATE_COMPLETE")
Expand All @@ -105,7 +109,7 @@ if [ -d ${WORKSPACE}/service/aws ]; then
echo "ERROR : Stack creation failed after ${TIME_SPENT} seconds. Please check the AWS console for more information."
exit 1
fi
echo "Success! The private IP of your new EC2 instance is $NODE_IP"
echo "Please use your provided key, ${AWS_KEYPAIR}, in order to SSH onto the instance."
Expand All @@ -119,7 +123,7 @@ if [ -d ${WORKSPACE}/service/aws ]; then
sleep "${SLEEP_TIME}"
COUNT=$((COUNT+1))
done
# Check that the instance has initalized and all tests have passed
TIME_SPENT=$(($COUNT * $SLEEP_TIME))
if $(aws ec2 describe-instance-status --instance-ids ${NEW_INSTANCE_ID} --query 'InstanceStatuses[0].InstanceStatus' --output text | grep -q "passed")
Expand All @@ -133,26 +137,26 @@ if [ -d ${WORKSPACE}/service/aws ]; then
if [ -f ${WORKSPACE}/service/aws/ec2-extension.conf ]; then
echo "#######################################"
echo "Adding EC2 instance to NGINX config using xip.io..."
export SERVICE_NAME="EC2-Service-Extension-${BUILD_NUMBER}"
cp ${WORKSPACE}/service/aws/ec2-extension.conf ec2-extension.conf
## Add nginx configuration
sed -i "s/###EC2_SERVICE_NAME###/${SERVICE_NAME}/" ec2-extension.conf
sed -i "s/###EC2_HOST_IP###/${NODE_IP}/" ec2-extension.conf
docker cp ec2-extension.conf proxy:/etc/nginx/sites-enabled/${SERVICE_NAME}.conf
## Reload nginx
docker exec proxy /usr/sbin/nginx -s reload
echo "You can check that your EC2 instance has been succesfully proxied by accessing the following URL: ${SERVICE_NAME}.${PUBLIC_IP}.xip.io"
else
echo "INFO: /service/aws/ec2-extension.conf not found"
fi
else
echo "INFO: /service/aws/service.template not found"
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ def loadPlatformExtensionCollectionJob = workflowJob(platformManagementFolderNam

// Setup Load_Cartridge Collection
loadPlatformExtensionCollectionJob.with{
description("This job loads a collection of platform extensions.")
parameters{
stringParam('COLLECTION_URL', '', 'URL to a JSON file defining your platform extension collection.')
credentialsParam("AWS_CREDENTIALS"){
credentialsParam("CREDENTIALS"){
type('com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl')
description('AWS access key and secret key for your account')
defaultValue('adop-default')
description('Platform extension credentials. Note: Leave at adop-default if credentials are not required.')
}
}
properties {
Expand Down Expand Up @@ -41,7 +43,7 @@ loadPlatformExtensionCollectionJob.with{
String url = data.extensions[i].url
println("Platform Extension URL: " + url)
String desc = data.extensions[i].description
build job: '/Platform_Management/Load_Platform_Extension', parameters: [[$class: 'StringParameterValue', name: 'GIT_URL', value: url], [$class: 'StringParameterValue', name: 'GIT_REF', value: 'master'], [$class: 'CredentialsParameterValue', name: 'AWS_CREDENTIALS', value: "${AWS_CREDENTIALS}"]]
build job: '/Platform_Management/Load_Platform_Extension', parameters: [[$class: 'StringParameterValue', name: 'GIT_URL', value: url], [$class: 'StringParameterValue', name: 'GIT_REF', value: 'master'], [$class: 'CredentialsParameterValue', name: 'CREDENTIALS', value: "${CREDENTIALS}"]]
}
}
Expand All @@ -57,4 +59,4 @@ loadPlatformExtensionCollectionJob.with{
sandbox()
}
}
}
}

0 comments on commit 76ae60f

Please sign in to comment.