diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc0e25e --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*terraform.tfstate* +*.tfvars +.terraform +*.tfstate +*.tfstate.backup +*.DS_STORE diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..cd18089 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,74 @@ +pipeline { + agent any + stages { + stage('Build') { + steps { + echo 'Initiating maven build' + sh 'mvn clean install -Dlicense.skip=true' + echo 'Maven build complete' + } + } + + stage('Testing') { + parallel { + stage('SonarQube Test') { + steps { + echo 'Initiating SonarQube test' + sh 'mvn sonar:sonar -Dsonar.host.url=http://:8081 -Dlicense.skip=true' + echo 'SonarQube test Complete' + } + } + + stage('Print Tester credentials') { + steps { + sleep 10 + echo "The tester is ${TESTER}" + } + } + stage('Print Build Number') { + steps { + sleep 20 + echo "This is build number ${BUILD_ID}" + } + } + } + } + + stage('JFrog Push') { + steps { + echo 'Starting JFrog push' + script { + def server = Artifactory.server "artifactory" + def buildInfo = Artifactory.newBuildInfo() + def rtMaven = Artifactory.newMavenBuild() + + rtMaven.tool = 'maven' + rtMaven.deployer server: server, releaseRepo: 'libs-release-local', snapshotRepo: 'libs-snapshot-local' + + buildInfo = rtMaven.run pom: 'pom.xml', goals: "clean install -Dlicense.skip=true" + buildInfo.env.capture = true + buildInfo.name = 'jpetstore-6' + server.publishBuildInfo buildInfo + } +echo 'JFrog push complete' + } +} + stage('Deploy prompt') { + steps { + input 'Deploy to Production?' + } + } + stage('Deploy') { + steps { + echo 'Initiating Deployment' + echo 'Deployment Complete' + } + } + } + tools { + maven 'maven' + } + environment { + TESTER = 'placeholder' + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..0b0db7f --- /dev/null +++ b/README.md @@ -0,0 +1,431 @@ +# Continuous Integration with Blue Ocean +![](images/BlueOceanOverview.png) + +- [Overview](#overview) +- [Hands On](#hands-on) + - [Pre-check](#pre-check) + - [Check Jenkins is running](#check-jenkins-is-running) + - [Check Artifactory is running](#check-artifactory-is-running) + - [Check Sonarqube is running](#check-sonarqube-is-running) + - [Setup](#setup) + - [Fork the JPetstore Repository](#fork-the-jpetstore-repository) + - [Prepare the JPetstore pom file](#prepare-the-jpetstore-pom-file) + - [Prepare Artifactory](#prepare-artifactory) + - [Prepare Jenkins](#prepare-jenkins) + - [Building the Pipeline](#building-the-pipeline) + - [Connecting Jenkins to the GitHub Repository](#connecting-jenkins-to-the-github-repository) + - [Defining the Jenkinsfile](#defining-the-jenkinsfile) +- [Conclusion](#conclusion) +- [Jenkins training](#jenkins-training) +- [Resources](#resources) +- [Appendix](#appendix) + - [Setting up the Playground Environment](#setting-up-the-playground-environment) + - [Tearing down the Playground Environment](#tearing-down-the-playground-environment) + - [Jenkinsfile code](#jenkinsfile-code) + +# Overview + +Cloudbees Jenkins is the most popular open source software orchestration tool on the market due to its wealth of plugins and easy set-up of infrastructure as code. Yet where does one begin using the Jenkinsfile for setting up new project and DevOps pipeline? + +Let Blue Ocean take the hassle of setting up a Jenkinsfile from scratch by providing an intuitive, modern coat of paint on Jenkins user interface. With its modern design and intuitive features, Blue Ocean is here to facilitate a quick and easy setup of new Jenkins pipeline with minimal hassle. + +In this playground, we will see how easy it is to set up a new Jenkins maven Job using the Blue Ocean plugin and the intuitive feedback it provides through its modern design. + + +# Hands-on + +## Pre-check + +### Check Jenkins is running + +In a separate tab, navigate to http://\:8080 and confirm Jenkins is up. + +![](images/JenkinsMainPageBase.png) + +### Check Artifactory is running + +In a separate tab, navigate to http://\:8081 and confirm Artifactory is up. + +![](images/ArtifactoryMainPage.png) + +(If you wish to login, default username and password is admin/password + +### Check SonarQube is running + +In a separate tab, navigate to http://\:8081 and confirm SonarQube is up. + +![](images/SonarqubeMainPage.png) + +(If you wish to login, default username and password is admin/password + +## Setup + +### Fork the JPetstore Repository + +1. Log into GitHub + +2. Fork the [JPetstore repository](https://github.com/mybatis/jpetstore-6) + +![](images/GithubJpetstoreRepo.png) + +### Prepare the JPetstore pom file + +Updates to the JPetstore pom file have been known to build errors. To pre-empt one such error, please remove **-SNAPSHOT** from the version field of the parent. + +![](images/PetstorePomXml.png) + +### Prepare Artifactory + +1. Go to Artifactory and login as admin; admin/password + +2. Go to the admin section on the left of the interface and click local + + ![](images/ArtifactoryAdminPage.png) + +3. Create 2 new maven repositories with the repository Key field as **libs-snapshot-local** and **libs-release-local** respctively. You may leave the rest of the fields as is. + +![](images/ArtifactoryNewRepo.png) + +### Prepare Jenkins + +1. In the Jenkins tab, click Manage Jenkins + + ![](images/JenkinsMainPageManageJenkins.png) + +2. Click Configure Systems and scroll to the Artifactory subsection + + ![](images/JenkinsConfigureSystem.png) + +3. Fill in the fields as follow: + + * Server ID: artifactory (all lowercase) + * URL: http://:8081/artifactory + * Username: admin + * Password: password + + ![](images/JenkinsArtifactoryConfiguration.png) + +4. Return back to Manage Jenkins page, click the Global Tool Configuration and scroll to the Maven subsection. + + ![](images/JenkinsGlobalToolConfiguration.png) + +5. Fill in the fields as follow: + + * Name: maven (all lowercase) + * MAVEN_HOME: /var/lib/apache-maven-3.6.0 + +![](images/JenkinsMavenToolConfiguration.png) + +## Building the Pipeline + +### Connecting Jenkins to the GitHub Repository + +1. Click Open Blue ocean + + ![](images/JenkinsMainPageBlueOcean.png) + +2. Click login on the top right with the credentials admin/password + +3. Click Create a new pipeline + + ![](images/BlueOceanMainPage.png) + +4. Select GitHub and click 'create an access token here' + + ![](images/BlueOceanCreatePipeline1.png) + + * You may need to log in to your github account again + +5. Fill in an appropriate description such as 'Playground_token'. You may review the permissions this token permits. Click Generate token when done + + ![](images/GithubAccessTokenCreation.png) + +6. Copy the newly created token to the clipboard and paste it into Jenkins + + ![](images/GithubTokenPage.png) + +7. After clicking connect, select the organisation you forked the JPetstore repository into. + + ![](images/BlueOceanCreatePipeline2.png) + +8. Select the JPetstore repository + + ![](images/BlueOceanCreatePipeline3.png) + +9. Click Create Pipeline and wait for Jenkins to create the Jenkinsfile + + ![](images/BlueOceanPipelinePage.png) + +### Defining the Jenkinsfile + +1. Click the plus sign and name the stage 'Build' + +2. Click Add steps to create the steps for the stages + +3. Select 'shellscript' and copy the following command: `mvn clean install -Dlicense.skip=true` + + * You may include Print message steps for ease of viewing and logging + + ![](images/BlueOceanPipelineBuild1.png) + +4. Create a new stage called 'Testing' with the following 'shellscript' step command: `mvn sonar:sonar -Dsonar.host.url=http://:8081 -Dlicense.skip=true` + +5. To introduce parallel stages, click the plus sign beneath the testing stage + + ![](images/BlueOceanPipelineBuild2.png) + +6. Before continuing, click the dot representing testing and rename it to 'SonarQube Test' + + ![](images/BlueOceanPipelineBuild3.png) + +7. Select the newly created parallel stage and name it 'Print Tester Credentials' with steps 'Print message' with `The tester is ${TESTER}` and 10s sleep. + + ![](images/BlueOceanPipelineBuild4.png) + +9. Create another parallel stage called 'Print build number', with steps 'Print message' with `This is build number ${BUILD_ID}` and 20s sleep. + + ![](images/BlueOceanPipelineBuild5.png) + +10. Bring up the pipeline editor by pressing ctrl+s for window users and command+s for MacOS users. + +11. Replace the single quotes of the previous 2 print steps, seen as echo in the Jenkinsfile, with double quotes + + * Without this step, Jenkins will be unable to inject Environmental values into the Build. + +12. Add the maven tool definition before the final curly brace in the Jenkinsfile; `tools {maven 'maven'}` + + ![](images/BlueOceanPipelineBuild6.png) + +13. Click Update to close the editor + +14. Create an environmental value using the interface on the right with the fields for 'Name' and 'Value' as 'TESTER' and 'your name' respectively + + ![](images/BlueOceanPipelineBuild7.png) + +15. Create a new stage called JFrog push and search for the 'Run arbitrary Pipeline script’ step and insert the following code + + ``` + def server = Artifactory.server "artifactory" + def buildInfo = Artifactory.newBuildInfo() + def rtMaven = Artifactory.newMavenBuild() + + rtMaven.tool = 'maven' + rtMaven.deployer server: server, releaseRepo: 'libs-release-local', snapshotRepo: 'libs-snapshot-local' + + buildInfo = rtMaven.run pom: 'pom.xml', goals: "clean install -Dlicense.skip=true" + buildInfo.env.capture = true + buildInfo.name = 'jpetstore-6' + server.publishBuildInfo buildInfo + ``` + + ![](images/BlueOceanPipelineBuild8.png) + +16. Add a new stage called 'Deploy prompt', selecting the 'Wait for interactive input' as the step, with the message field filled as 'Deploy to Production?' + + ![](images/BlueOceanPipelineBuild9.png) + +17. For the final stage, name it Deployment and add placeholder 'Print message' steps. + + ![](images/BlueOceanPipelineBuild10.png) + +18. To save and upload the Jenkinsfile to the github repository, click Save on the top right, with an appropriate description for the change like 'initial Jenkinsfile creation'. + +19. Click save and run to upload the file and trigger the Jenkins Build. + + ![](images/BlueOceanPipelineBuild10.png) + +20. When completed, you may go to the respective URLs for Artifactory and SonarQube to see the Artefacts and test results respectively. + +# Conclusion + +In this playground we had an environment containing a build server (Jenkins) and a code review platform (SonarQube), along with another server containing a package repository (Artifactory). We built a CI pipeline using the Blue Ocean plugin and saved it as code; pipeline as code. We also saw how to inject custom and pre-determined Jenkins Environmental values into the script. + +There are plenty of options available for building on top of the playground such as: + +* Preparing a proper Deployment stage to automate the deployment process of the Jenkins Project. +* Setting up email notifications that automatically gets triggered and sent when a job succeeds or fails. +* Implement other automated testing stages to run in parallel to the SonarQube test. +* Run the build processes in other Operating systems and using other Java versions in parallel. + +# Jenkins Training + +If you would like to further your knowledge with the Jenkins product suite. Consider booking a training course with one of ECS Digital certified Jenkins trainers. + +For more information check out the link below: + +https://ecs-digital.co.uk/what-we-do/training + +# Resources +### Hashicorp Terraform + +Product Details +https://www.terraform.io/ + +Documentation +https://www.terraform.io/docs/index.html + + +### Jenkins + +Product Details +https://jenkins.io/ + +Documentation +https://jenkins.io/doc/ + + +### Blue Ocean + +Product Details +https://jenkins.io/projects/blueocean/ + +Documentaion +https://jenkins.io/doc/book/blueocean/ + + +### Artifactory + +Product Details +https://jfrog.com/artifactory/ + +Documentation +https://www.jfrog.com/confluence/pages/viewpage.action?pageId=46107472 + + +### SonarQube + +Product Details +https://www.sonarqube.org/ + +Documentation +https://docs.sonarqube.org/latest/ + + +### Maven + +Product Details +https://maven.apache.org/ + +Documentation +https://maven.apache.org/guides/index.html + + +# Appendix + +### Setting up the Playground Environment + +Ensure you have the latest version of terraform installed. + +Set the following environment variables: + +``` +$export AWS_ACCESS_KEY_ID= +$export AWS_SECRET_ACCESS_KEY= +``` + +Navigate to the _setup directory and execute: + +``` +$terraform init +``` + +Then execute: +``` +$terraform plan +``` + +Finally, run the following and specify the number of instances you want to create: + +``` +$terraform apply -var count_var=1 +``` + + +### Tearing down the Playground Environment + +Navigate to the _setup directory and execute: + +``` +$terraform destroy +``` + +### Jenkinsfile code + +``` +pipeline { + agent any + stages { + stage('Build') { + steps { + echo 'Initiating maven build' + sh 'mvn clean install -Dlicense.skip=true' + echo 'Maven build complete' + } + } + + stage('Testing') { + parallel { + stage('SonarQube Test') { + steps { + echo 'Initiating SonarQube test' + sh 'mvn sonar:sonar -Dsonar.host.url=http://:8081 -Dlicense.skip=true' + echo 'SonarQube test Complete' + } + } + + stage('Print Tester credentials') { + steps { + sleep 10 + echo "The tester is ${TESTER}" + } + } + stage('Print Build Number') { + steps { + sleep 20 + echo "This is build number ${BUILD_ID}" + } + } + } + } + + stage('JFrog Push') { + steps { + echo 'Starting JFrog push' + script { + def server = Artifactory.server "artifactory" + def buildInfo = Artifactory.newBuildInfo() + def rtMaven = Artifactory.newMavenBuild() + + rtMaven.tool = 'maven' + rtMaven.deployer server: server, releaseRepo: 'libs-release-local', snapshotRepo: 'libs-snapshot-local' + + buildInfo = rtMaven.run pom: 'pom.xml', goals: "clean install -Dlicense.skip=true" + buildInfo.env.capture = true + buildInfo.name = 'jpetstore-6' + server.publishBuildInfo buildInfo + } +echo 'JFrog push complete' + } +} + stage('Deploy prompt') { + steps { + input 'Deploy to Production?' + } + } + stage('Deploy') { + steps { + echo 'Initiating Deployment' + echo 'Deployment Complete' + } + } + } + tools { + maven 'maven' + } + environment { + TESTER = 'placeholder' + } +} + + +``` diff --git a/_setup/config_files/README.md b/_setup/config_files/README.md new file mode 100644 index 0000000..d5b1868 --- /dev/null +++ b/_setup/config_files/README.md @@ -0,0 +1,13 @@ +# config_files + +## admin_accnt_config +A default admin account being created + +## hudson.tasks.Maven.xml +Contains the definition of the global tool configuration for 1 Maven tool called maven and in directory /var/lib/apache-maven-3.6.0 + +## jenkins_config.xml +The general config file of Jenkins + +## sonar +The file to be placed in init.d for setting up sonarqube as a service. diff --git a/_setup/config_files/admin_accnt_config.xml b/_setup/config_files/admin_accnt_config.xml new file mode 100644 index 0000000..45515f9 --- /dev/null +++ b/_setup/config_files/admin_accnt_config.xml @@ -0,0 +1,37 @@ + + + admin + + + + + + + + + + + all + false + false + + + + + + + + + true + + + #jbcrypt:$2a$10$mGgU.Pm8TANTvr4XLfmXtuLJJ43hcMSYbBys/Hjb9g8iC.KbkFupS + + + + authenticated + + 1543199685069 + + + \ No newline at end of file diff --git a/_setup/config_files/jenkins_config.xml b/_setup/config_files/jenkins_config.xml new file mode 100644 index 0000000..9085e1c --- /dev/null +++ b/_setup/config_files/jenkins_config.xml @@ -0,0 +1,38 @@ + + + + 2.138.3 + RUNNING + 2 + NORMAL + true + + + false + false + + false + + ${JENKINS_HOME}/workspace/${ITEM_FULL_NAME} + ${ITEM_ROOTDIR}/builds + + + + + + 0 + + + + all + false + false + + + + all + 0 + + + + \ No newline at end of file diff --git a/_setup/config_files/sonar b/_setup/config_files/sonar new file mode 100644 index 0000000..a293232 --- /dev/null +++ b/_setup/config_files/sonar @@ -0,0 +1,18 @@ +#!/bin/sh +# +# rc file for SonarQube +# +# chkconfig: 345 96 10 +# description: SonarQube system (www.sonarsource.org) +# +### BEGIN INIT INFO +# Provides: sonar +# Required-Start: $network +# Required-Stop: $network +# Default-Start: 3 4 5 +# Default-Stop: 0 1 2 6 +# Short-Description: SonarQube system (www.sonarsource.org) +# Description: SonarQube system (www.sonarsource.org) +### END INIT INFO + +/usr/bin/sonar $* diff --git a/_setup/constants.tf b/_setup/constants.tf new file mode 100644 index 0000000..e8c3f13 --- /dev/null +++ b/_setup/constants.tf @@ -0,0 +1,8 @@ +/* +Holds the "constants" used throughout the terraform code for ease of changing +*/ + +variable "playground_date" { + type = "string" + description = "format MMMYYYY" +} diff --git a/_setup/instance.tf b/_setup/instance.tf new file mode 100644 index 0000000..4780ec7 --- /dev/null +++ b/_setup/instance.tf @@ -0,0 +1,71 @@ +/* +The configuration file for setting up instances +*/ + +variable "jenkins_key" { + type = "string" +} + +variable "jenkins_key_name" { + type = "string" +} + +variable "count_var" {} + +resource "aws_instance" "pg_instance_1" { + ami = "ami-08569b978cc4dfa10" + count = "${var.count_var}" + instance_type = "t2.medium" + subnet_id = "${aws_subnet.pg_subnet.id}" + vpc_security_group_ids = ["${aws_default_security_group.pg_d_sg.id}"] + key_name = "${var.jenkins_key_name}" + + connection { + type = "ssh" + user = "ec2-user" + private_key = "${file("~/.ssh/${var.jenkins_key}")}" + } + + provisioner "file" { + source = "config_files/" + destination = "/tmp" + } + + provisioner "remote-exec" { + scripts = [ + "scripts/jenkins.sh", + "scripts/jenkins_master_config.sh", + "scripts/jenkins_agent_config.sh", + "scripts/sonarqube_linux_installation.sh", + ] + } + + tags { + Name = "${var.playground_date}_playground AWS instance 1" + } +} + +resource "aws_instance" "pg_instance_2" { + ami = "ami-08569b978cc4dfa10" + count = "${var.count_var}" + instance_type = "t2.small" + subnet_id = "${aws_subnet.pg_subnet.id}" + vpc_security_group_ids = ["${aws_default_security_group.pg_d_sg.id}"] + key_name = "${var.jenkins_key_name}" + + connection { + type = "ssh" + user = "ec2-user" + private_key = "${file("~/.ssh/${var.jenkins_key}")}" + } + + provisioner "remote-exec" { + scripts = [ + "scripts/artifactory_installation.sh", + ] + } + + tags { + Name = "${var.playground_date}_playground AWS instance 2" + } +} diff --git a/_setup/network.tf b/_setup/network.tf new file mode 100644 index 0000000..7e8cf30 --- /dev/null +++ b/_setup/network.tf @@ -0,0 +1,108 @@ +/* +The configuration file for setting up the initial network configurations +*/ + +provider "aws" { + region = "ap-southeast-1" +} + +resource "aws_vpc" "pg_vpc" { + cidr_block = "192.0.0.0/16" + + tags { + Name = "${var.playground_date}_playground virtual private network" + } +} + +resource "aws_subnet" "pg_subnet" { + vpc_id = "${aws_vpc.pg_vpc.id}" + cidr_block = "192.0.0.0/24" + availability_zone = "ap-southeast-1a" + + map_public_ip_on_launch = true + + tags { + Name = "${var.playground_date}_playground subnet" + } +} + +resource "aws_internet_gateway" "pg_igw" { + vpc_id = "${aws_vpc.pg_vpc.id}" + + tags { + Name = "${var.playground_date}_playground internet gateway" + } +} + +resource "aws_default_security_group" "pg_d_sg" { + vpc_id = "${aws_vpc.pg_vpc.id}" + + ingress { + protocol = "tcp" + self = true + from_port = 22 + to_port = 22 + cidr_blocks = ["0.0.0.0/0"] + description = "SSH port" + } + + ingress { + protocol = "tcp" + self = true + from_port = 8080 + to_port = 8080 + cidr_blocks = ["0.0.0.0/0"] + description = "Jenkins port" + } + + ingress { + protocol = "tcp" + self = true + from_port = 9000 + to_port = 9000 + cidr_blocks = ["0.0.0.0/0"] + description = "SonarQube port" + } + + ingress { + protocol = "tcp" + self = true + from_port = 8081 + to_port = 8081 + cidr_blocks = ["0.0.0.0/0"] + description = "JFrog Artifactory port" + } + + ingress { + protocol = "tcp" + self = true + from_port = 8082 + to_port = 8082 + cidr_blocks = ["0.0.0.0/0"] + description = "Nexus port" + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags { + Name = "${var.playground_date}_playground default security group" + } +} + +resource "aws_default_route_table" "pg_d_rt" { + default_route_table_id = "${aws_vpc.pg_vpc.default_route_table_id}" + + route { + cidr_block = "0.0.0.0/0" + gateway_id = "${aws_internet_gateway.pg_igw.id}" + } + + tags { + Name = "${var.playground_date}_playground default route table" + } +} diff --git a/_setup/output.tf b/_setup/output.tf new file mode 100644 index 0000000..3463e26 --- /dev/null +++ b/_setup/output.tf @@ -0,0 +1,33 @@ +/* +The configuration file for defining the output +*/ + +output "public_ip_1" { + description = "Public ip of instance 1" + value = "${aws_instance.pg_instance_1.*.public_ip}" +} + +output "public_ip_1_jenkins" { + description = "Public ip of Jenkins on instance 1" + value = "${formatlist("%s:%s",aws_instance.pg_instance_1.*.public_ip,"8080")}" +} + +output "public_ip_1_SonarQube" { + description = "Public ip of SonarQube on instance 1" + value = "${formatlist("%s:%s",aws_instance.pg_instance_1.*.public_ip,"8081")}" +} + +output "public_ip_2" { + description = "Public ip of instance 2" + value = "${aws_instance.pg_instance_2.*.public_ip}" +} + +output "public_ip_2_Artifactory" { + description = "Public ip of Artifactory on instance 2" + value = "${formatlist("%s:%s",aws_instance.pg_instance_2.*.public_ip,"8081")}" +} + +output "artifactory_URL" { + description = "Artifactory URL for use in Jenkins tool" + value = "${formatlist("http://%s:%s/artifactory",aws_instance.pg_instance_2.*.public_ip,"8081")}" +} diff --git a/_setup/scripts/artifactory_installation.sh b/_setup/scripts/artifactory_installation.sh new file mode 100644 index 0000000..c8a8d7f --- /dev/null +++ b/_setup/scripts/artifactory_installation.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +### artifactory_installation.sh +# This shellscript installs artfiactory on a linux machine, specifically on a x86_64 Linux system + +echo Starting Artifactory installation procedure + +# Remove default Java and install version known to work with SonarQube +sudo yum remove java -y +sudo yum install java-1.8.0-openjdk-devel -y + +sleep 30s # give time for yum to complete installation and release it to + +# Install artifactory as a service +sudo wget https://bintray.com/jfrog/artifactory-rpms/rpm -O bintray-jfrog-artifactory-rpms.repo +sudo mv bintray-jfrog-artifactory-rpms.repo /etc/yum.repos.d/ +sudo yum install jfrog-artifactory-oss -y +sudo service artifactory start +sudo chkconfig artifactory on + +echo Artifactory installation procedure completed diff --git a/_setup/scripts/jenkins.sh b/_setup/scripts/jenkins.sh new file mode 100644 index 0000000..34fdfc1 --- /dev/null +++ b/_setup/scripts/jenkins.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +### jenkins.sh +# This shellscript is responsible for installing Jenkins. +# Tested on an amazon linux machine + +echo Starting Jenkins installation procedure + +# Remove default Java and install version known to work with Jenkins +sudo yum remove java -y +sudo yum install java-1.8.0-openjdk-devel -y + +# Initial installation of Jenkins. Disable prompt for Admin password and suggested plugins +sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo +sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key +sudo yum install jenkins -y +sudo sed -i 's/JENKINS_JAVA_OPTIONS.*/JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false -Xmx1024m -XX:MaxPermSize=512m"/' /etc/sysconfig/jenkins + +# Installation of plugins and dependencies using Jenkins CLI +sudo service jenkins start + +sudo chkconfig jenkins on + +echo Jenkins installation procedure completed diff --git a/_setup/scripts/jenkins_agent_config.sh b/_setup/scripts/jenkins_agent_config.sh new file mode 100644 index 0000000..1d3b6af --- /dev/null +++ b/_setup/scripts/jenkins_agent_config.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +### jenkins_agent_config.sh +# This shellscript installs and sets the environmental variables needed for the Jenkins agent to run +# Tested on amazon linux machine + +echo Starting Jenkins agent configuration procedure + +# Installing git +sudo yum install git -y + +# Installing maven +cd /var/lib +sudo wget https://www-eu.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz +sudo tar -xf apache-maven-3.6.0-bin.tar.gz + +# Set maven environmental values +export M2_HOME=/var/lib/apache-maven-3.6.0 +echo export M2_HOME=/var/lib/apache-maven-3.6.0 >> ~/.bash_profile +export M2=$M2_HOME/bin +echo export M2=$M2_HOME/bin >> ~/.bash_profile +export PATH=$M2:$PATH +echo export PATH=$M2:$PATH >> ~/.bash_profile +mvn -v + +echo Jenkins agent configuration procedure completed diff --git a/_setup/scripts/jenkins_master_config.sh b/_setup/scripts/jenkins_master_config.sh new file mode 100644 index 0000000..b30f0b9 --- /dev/null +++ b/_setup/scripts/jenkins_master_config.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +### jenkins_master_config.sh +# This shellscript sets up the configuration of the Jenkins master, such as security configuration and accounts. +# Also installs the plugins, along with necessary dependencies +# Tested on amazon linux machine + +echo Starting Jenkins master configuration procedure + +sleep 30s #DO NOT DELETE. Setting some time for Jenkins to get up and running facilitates the installation of plugins + +# Override the default jenkins config file +sudo mv /tmp/jenkins_config.xml /var/lib/jenkins/config.xml + +# Make the directory to place the admin account config file in +sudo mkdir /var/lib/jenkins/users +sudo mkdir /var/lib/jenkins/users/admin +sudo mv /tmp/admin_accnt_config.xml /var/lib/jenkins/users/admin/config.xml + +# Set the owner of the entire jenkins directory to jenkins. Jenkins will not work if permissions are different +sudo chown -R jenkins:jenkins /var/lib/jenkins + +wget localhost:8080/jnlpJars/jenkins-cli.jar +java -jar jenkins-cli.jar -s http://localhost:8080/ install-plugin blueocean +java -jar jenkins-cli.jar -s http://localhost:8080/ install-plugin artifactory +sudo service jenkins restart + +echo Jenkins master configuration procedure completed diff --git a/_setup/scripts/sonarqube_linux_installation.sh b/_setup/scripts/sonarqube_linux_installation.sh new file mode 100644 index 0000000..8129f5c --- /dev/null +++ b/_setup/scripts/sonarqube_linux_installation.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +### sonarqube_linux_installation.sh +# This shellscript installs sonarqube on a linux machine, specifically on a x86_64 Linux system + +echo Starting SonarQube installation procedure + +# Remove default Java and install version known to work with SonarQube +sudo yum remove java -y +sudo yum install java-1.8.0-openjdk-devel -y + +# Get the installation zip file and unzip it +sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-6.7.6.zip +sudo mkdir /etc/sonarqube +sudo unzip -qq sonarqube-6.7.6.zip -d /etc/sonarqube/ + +# setup sonarqube to run as a service +sudo mv /tmp/sonar /etc/init.d +sudo ln -s /etc/sonarqube/sonarqube-6.7.6/bin/linux-x86-64/sonar.sh /usr/bin/sonar +sudo chmod 755 /etc/init.d/sonar +sudo chown root:root /etc/init.d/sonar +sudo chkconfig --add sonar +sudo sed -i 's/wrapper.java.command=java/wrapper.java.command=\/usr\/lib\/jvm\/jre\/bin\/java/' /etc/sonarqube/sonarqube-6.7.6/conf/wrapper.conf + +# Change sonar port to 8081 +sudo sed -i 's/#sonar.web.port=9000/sonar.web.port=8081/' /etc/sonarqube/sonarqube-6.7.6/conf/sonar.properties + +# Create sonar user and change file permissions +sudo useradd sonar +sudo sed -i 's/#RUN_AS_USER=/RUN_AS_USER=sonar/' /etc/sonarqube/sonarqube-6.7.6/bin/linux-x86-64/sonar.sh +sudo chown -R sonar:sonar /etc/sonarqube + +sudo service sonar start + +# Show logs for verifying setup is successful +sleep 10s +sudo cat /etc/sonarqube/sonarqube-6.7.6/logs/sonar.log +# sudo cat /etc/sonarqube/sonarqube-6.7.6/logs/es.log + +echo SonarQube installation procedure completed diff --git a/images/ArtifactoryAdminPage.png b/images/ArtifactoryAdminPage.png new file mode 100644 index 0000000..f167e5e Binary files /dev/null and b/images/ArtifactoryAdminPage.png differ diff --git a/images/ArtifactoryMainPage.png b/images/ArtifactoryMainPage.png new file mode 100644 index 0000000..d95cb38 Binary files /dev/null and b/images/ArtifactoryMainPage.png differ diff --git a/images/ArtifactoryNewRepo.png b/images/ArtifactoryNewRepo.png new file mode 100644 index 0000000..9e5909f Binary files /dev/null and b/images/ArtifactoryNewRepo.png differ diff --git a/images/BlueOceanCreatePipeline1.png b/images/BlueOceanCreatePipeline1.png new file mode 100644 index 0000000..d5388ae Binary files /dev/null and b/images/BlueOceanCreatePipeline1.png differ diff --git a/images/BlueOceanCreatePipeline2.png b/images/BlueOceanCreatePipeline2.png new file mode 100644 index 0000000..ef6080d Binary files /dev/null and b/images/BlueOceanCreatePipeline2.png differ diff --git a/images/BlueOceanCreatePipeline3.png b/images/BlueOceanCreatePipeline3.png new file mode 100644 index 0000000..d2e2f32 Binary files /dev/null and b/images/BlueOceanCreatePipeline3.png differ diff --git a/images/BlueOceanMainPage.png b/images/BlueOceanMainPage.png new file mode 100644 index 0000000..c795318 Binary files /dev/null and b/images/BlueOceanMainPage.png differ diff --git a/images/BlueOceanOverview.png b/images/BlueOceanOverview.png new file mode 100644 index 0000000..96a1945 Binary files /dev/null and b/images/BlueOceanOverview.png differ diff --git a/images/BlueOceanPipelineBuild1.png b/images/BlueOceanPipelineBuild1.png new file mode 100644 index 0000000..b4ac86b Binary files /dev/null and b/images/BlueOceanPipelineBuild1.png differ diff --git a/images/BlueOceanPipelineBuild10.png b/images/BlueOceanPipelineBuild10.png new file mode 100644 index 0000000..fa30f53 Binary files /dev/null and b/images/BlueOceanPipelineBuild10.png differ diff --git a/images/BlueOceanPipelineBuild11.png b/images/BlueOceanPipelineBuild11.png new file mode 100644 index 0000000..aeb1b91 Binary files /dev/null and b/images/BlueOceanPipelineBuild11.png differ diff --git a/images/BlueOceanPipelineBuild2.png b/images/BlueOceanPipelineBuild2.png new file mode 100644 index 0000000..8d59b74 Binary files /dev/null and b/images/BlueOceanPipelineBuild2.png differ diff --git a/images/BlueOceanPipelineBuild3.png b/images/BlueOceanPipelineBuild3.png new file mode 100644 index 0000000..7e33990 Binary files /dev/null and b/images/BlueOceanPipelineBuild3.png differ diff --git a/images/BlueOceanPipelineBuild4.png b/images/BlueOceanPipelineBuild4.png new file mode 100644 index 0000000..d6c1644 Binary files /dev/null and b/images/BlueOceanPipelineBuild4.png differ diff --git a/images/BlueOceanPipelineBuild5.png b/images/BlueOceanPipelineBuild5.png new file mode 100644 index 0000000..ad78c85 Binary files /dev/null and b/images/BlueOceanPipelineBuild5.png differ diff --git a/images/BlueOceanPipelineBuild6.png b/images/BlueOceanPipelineBuild6.png new file mode 100644 index 0000000..24f2979 Binary files /dev/null and b/images/BlueOceanPipelineBuild6.png differ diff --git a/images/BlueOceanPipelineBuild7.png b/images/BlueOceanPipelineBuild7.png new file mode 100644 index 0000000..8cb3465 Binary files /dev/null and b/images/BlueOceanPipelineBuild7.png differ diff --git a/images/BlueOceanPipelineBuild8.png b/images/BlueOceanPipelineBuild8.png new file mode 100644 index 0000000..900cdd1 Binary files /dev/null and b/images/BlueOceanPipelineBuild8.png differ diff --git a/images/BlueOceanPipelineBuild9.png b/images/BlueOceanPipelineBuild9.png new file mode 100644 index 0000000..5a19011 Binary files /dev/null and b/images/BlueOceanPipelineBuild9.png differ diff --git a/images/BlueOceanPipelinePage.png b/images/BlueOceanPipelinePage.png new file mode 100644 index 0000000..0efb42a Binary files /dev/null and b/images/BlueOceanPipelinePage.png differ diff --git a/images/GithubAccessTokenCreation.png b/images/GithubAccessTokenCreation.png new file mode 100644 index 0000000..1279394 Binary files /dev/null and b/images/GithubAccessTokenCreation.png differ diff --git a/images/GithubJpetstoreRepo.png b/images/GithubJpetstoreRepo.png new file mode 100644 index 0000000..fee6357 Binary files /dev/null and b/images/GithubJpetstoreRepo.png differ diff --git a/images/GithubTokenPage.png b/images/GithubTokenPage.png new file mode 100644 index 0000000..d4fee20 Binary files /dev/null and b/images/GithubTokenPage.png differ diff --git a/images/JenkinsArtifactoryConfiguration.png b/images/JenkinsArtifactoryConfiguration.png new file mode 100644 index 0000000..683b992 Binary files /dev/null and b/images/JenkinsArtifactoryConfiguration.png differ diff --git a/images/JenkinsConfigureSystem.png b/images/JenkinsConfigureSystem.png new file mode 100644 index 0000000..c949c89 Binary files /dev/null and b/images/JenkinsConfigureSystem.png differ diff --git a/images/JenkinsGlobalToolConfiguration.png b/images/JenkinsGlobalToolConfiguration.png new file mode 100644 index 0000000..9f99aa6 Binary files /dev/null and b/images/JenkinsGlobalToolConfiguration.png differ diff --git a/images/JenkinsMainPageBase.png b/images/JenkinsMainPageBase.png new file mode 100644 index 0000000..8ac9abf Binary files /dev/null and b/images/JenkinsMainPageBase.png differ diff --git a/images/JenkinsMainPageBlueOcean.png b/images/JenkinsMainPageBlueOcean.png new file mode 100644 index 0000000..15ca495 Binary files /dev/null and b/images/JenkinsMainPageBlueOcean.png differ diff --git a/images/JenkinsMainPageManageJenkins.png b/images/JenkinsMainPageManageJenkins.png new file mode 100644 index 0000000..9b388a0 Binary files /dev/null and b/images/JenkinsMainPageManageJenkins.png differ diff --git a/images/JenkinsMavenToolConfiguration.png b/images/JenkinsMavenToolConfiguration.png new file mode 100644 index 0000000..edc111b Binary files /dev/null and b/images/JenkinsMavenToolConfiguration.png differ diff --git a/images/PetstorePomXml.png b/images/PetstorePomXml.png new file mode 100644 index 0000000..1dd5b7e Binary files /dev/null and b/images/PetstorePomXml.png differ diff --git a/images/SonarqubeMainScreen.png b/images/SonarqubeMainScreen.png new file mode 100644 index 0000000..3ff01d2 Binary files /dev/null and b/images/SonarqubeMainScreen.png differ