This repository holds the details of actions needed to be performed for the Live Learning Lab (L3) "An Introduction to Jenkins" by Shariq Mustaquim - sharmus@
-
Login to AWS Console
-
Change region to Sydney (ap-southeast-2)
-
Create a KeyPair and save the private '.pem' key in a local directory
-
Clone this GitHub repo
git clone https://github.com/shariqmus/intro_to_jenkins.git
-
Change directory to cloned folder
cd intro_to_jenkins
-
Run the following Command to create the stack (Update the <key_name> parameter):
aws cloudformation create-stack --region ap-southeast-2 --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM --template-body file://template.yml --stack-name introToJenkins --parameters ParameterKey=KeyName,ParameterValue=<key_name>
-
Wait for the stack to complete provisioning resources
-
Run the following command to find the endpoint URL of Jenkins server
aws cloudformation describe-stacks --region ap-southeast-2 --query "Stacks[*].Outputs[?OutputKey=='JenkinsMasterURL'].OutputValue" --output text
-
Navigate to the URL in browser
-
Run the following command to find the SSH command to connect to the server:
aws cloudformation describe-stacks --region ap-southeast-2 --query "Stacks[*].Outputs[?OutputKey=='JenkinsMasterSSH'].OutputValue" --output text
-
Run the above command in terminal to SSH into the Jenkins master Linux EC2 instance
-
'cd' to directory where you save the private 'pem' key and run the command from the above step to SSH into the EC2 instance.
-
Find the password in the EC2 instance:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
-
Add the password to Jenkins UI and click continue
-
Accept default plugins
-
Create an admin user and
make sure to remember the username and password
-
Click 'Save and Continue', 'Save and Finish' and 'Start using Jenkins' button.
-
On the Home page, Click Credentials > System > 'Global credentials (unrestricted)' > Add Credentials
-
Select Kind as 'SSH Username with private key'
-
Type the following:
- Username: ec2-user
- Private Key: Enter directly
- Key: Copy/Paste the Private key (.pem file) created in 'Install Jenkins' Step #2.
-
Login to the Jenkins UI
-
Click 'Build Executor Status' on the home page
-
Click 'Configure' (Gear Icon) and set '# of executors' to 0, then click 'Save', you will see no executor under 'Build Executor Status' now.
-
Click 'Build Executor Status' on the home page again
-
Click 'New Node', in Node name enter 'build-agent-1', select 'Permanent agent' and click 'OK'
-
Type the following on the next page:
- Description: Amazon Linux 2
- # of executors: 4
- Remote Root Directory: /home/ec2-user
- Labels: beanstalk
- Launch method: Launch slave agents via SSH
-
Host: (Type the result retrieved from running the following command to find the Private Dns name of Build agent):
aws cloudformation describe-stacks --region ap-southeast-2 --query "Stacks[*].Outputs[?OutputKey=='JenkinsBuildAgentPrivateDnsName'].OutputValue" --output text
-
Credentials: ec2-user
-
Host key Verification Strategy: Non verifying Verification Strategy
-
Click 'Save'
-
Go to Home Page again and click 'build-agent-1' from section 'Build Executor Status', then click the 'Log' link to confirm agent was successfully connected by looking for a log entry at end:
"Agent successfully connected and online"
-
Login and navigate to the Jenkins UI
-
Click 'Manage Jenkins' from the left hand menu and click 'Configure System'
-
Locate the 'GitHub' section
-
Click 'Advanced' button
-
From 'Additional actions' drop-down, select 'Convert login and password to token'
-
Click the radio button 'From login and password'
-
Enter your GitHub username and password, then click 'Create token credentials'
-
You should see a confirmation
Created credentials with id <id...>
-
Click 'Save'
(Optional: Confirm Jenkins created a Personal Access Token in GitHub)
- Open a browser tab and login to your GitHub account
- Click on your Profile Picture in top right of page
- Click Settings > Developer Settings > Personal Access Tokens
- Confirm 'Jenkins Github Plugin token' exists
- Click and view the scopes (i.e permissions) defined for the Token
- Leave the GitHub browser window open
-
Open a browser tab and login to your GitHub account (if not already logged in)
-
Go to the following URL: https://github.com/shariqmus/eb-python
-
Click 'Fork' button on the top right to fork the repo in your own account
-
Go to 'Settings' under the repository (with Gear Icon)
-
Click Webhooks from left side navigation
-
Click 'Add webhook'
-
Run the following command on a terminal to obtain the WebHook URL:
aws cloudformation describe-stacks --region ap-southeast-2 --query "Stacks[*].Outputs[?OutputKey=='JenkinsGitHubWebHookURL'].OutputValue" --output text
-
Copy the URL obtained from above command output to 'Payload URL' field
-
Click 'Add webhook' button
-
Leave the browser window open
- Login/Navigate to Jenkins homepage
- Click 'New Item'
- Enter item name as 'my-eb-app'
- Enter description as "Deploy to beanstalk"
- Select the check-box 'Restrict where this project can be run' and type: 'beanstalk' (should match the label on the build agent configured)
- Click 'Source Code Management' tab:
- Select Git radio-button and copy the clone URL of the repository forked in 'Create a Code Repository' for Application Step#3
- In 'Additional Behaviours', click 'Add' and select 'Check out to specific local branch'
- Click 'Build Triggers' tab:
- Select 'GitHub hook trigger for GITScm polling'
- Click 'Build' tab:
-
Click 'Add build step' > 'Execut shell'
-
Type the following:
# Initialize beanstalk application eb init my-eb-app --platform python-3.6 --region ap-southeast-2 # Use environment named 'DevelopmentEnvironment' eb use DevelopmentEnvironment # deploy new version eb deploy # report on deployment status eb health eb status
-
-
Open a browser tab and login to your GitHub account (if not already logged in)
-
Go to the 'eb-python' repository in your account
-
Click 'application.py' file
-
Click the pencil icon on the top-right of the editor window to edit the file
-
Search for word 'Congratulations'
-
Update it to say: 'Congratulations - your name'
-
Click 'Commit changes'
-
Navigate to Jenkins homepage and confirm a build is started as soon as the commit was performed.
-
Check the Console output under the Build in Jenkins by clicking build number (e.g. '#2') and the 'Console Output'
-
Navigate to Beanstalk environment URL and confirm your changes were deployed. You can find the EB environment URL using this command:
aws cloudformation describe-stacks --region ap-southeast-2 --query "Stacks[*].Outputs[?OutputKey=='EBEnvironmentURL'].OutputValue" --output text
-
Finally delete the stack to cleanup the resources:
aws cloudformation delete-stack --region ap-southeast-2 --stack-name introToJenkins