Team :
- Nikhil Katre ([email protected])
- Pengyu Li ([email protected])
Submission: Milestone#1
Link To Project Code: WebGoat
Submission Files:
- Config File Of Jenkins
- Config File Of WebGoat Project
- Screenshots
- README.md
The following steps demonstrate the setup for this Milestone
- Select WebGoat project on git.
- Download and Install java 8 update 31 and git
- Download jenkins.war file
- Goto directory where jenkins.war is present and execute the command
java -jar jenkins.war
- After the
winstone server
starts running we will get the following screen - This indicates that Jenkins is deployed and running properly
- Goto Dashboard of Jenkins and click on
New Item
, now enter theItem name
as the name of the project that we want to work with. (We are working with WebGoat Project) - Select type of project as
Freestyle project
and clickOK
- Goto Jenkins
Dashboard
>Manage Jenkins
>Manage Plugins
. - Click on
Available
and install GitHub Plugin - Goto Jenkins
Dashboard
>WebGoat
>Configure
- Now in
Source Control Management
enter Repository URL as https://github.com/nkatre/WebGoat and link your github credentials with this repository as shown in the figure below - You can also fork the original repository WebGoat in your github account and make the same changes as we performed in this milestone using your github credentials.
To install plugins, goto Jenkins Dashboard
> Manage Jenkins
> Manage Plugins
Plugins installed for this milestone:
- GitHub Plugin
- NodeLabel Parameter Plugin
- Maven Project Plugin
- Config File Provider Plugin
- Git Plugin
- Git Client Plugin
- Managed Script Plugin
- GitHub API Plugin
- Parameterized Trigger Plugin
- SCM API Plugin
Milestone#1 is evaluated based on the following
Evaluation Parameters:
- Triggered Builds - 20%
The ability to trigger a build in response to a git commit via a git hook.- Dependency Management - 20%
The ability to setup dependencies for the project and restore to a clean state.- Build Script Execution - 20%
The ability to execute a build script (e.g., shell, maven)- Multiple Nodes - 20%
The ability to run a build on multiple nodes (e.g. jenkins slaves, go agents, or a spawned droplet/AWS.).- Status - 20%
The ability to retrieve the status of the build via http.
We have used Poll SCM feature of Jenkins to achieve build trigger.
The following steps were followed to achieve build trigger.
- Install Github plugin in Jenkins
- Goto
Configure
option in Jenkins project. - In
Build Triggers
, select the options as shown in the image below
- Build when a change is pushed to github
- Poll SCM
- In the Schedule, type
*/5 * * * *
which indicates that the git repository will be polled for every 5 minutes.
If a change is identified in the repository then the project will be build in Jenkins
- I create a sample file called sampleFile and add this to the project WebGoat
- In the next git poll, Jenkins identifies the changes made to the repository and hence builds the project automatically on identifying changes.
Output of build triggered by changes to Project
- We achieve this by configuring maven in Jenkins
- In the Project Configuration, we invoke maven and set goal to
clean install
- To demonstrate this, a dependency is added in
pom.xml
file of the project - When the project is build then this dependency is also included in the project which can be seen in console output in Jenkins.
Steps for maven configuration
- Install Maven Project Plugin in Jenkins
- Goto
Manage Jenkins
>Configure System
. - In
Maven Configuration
, set the following - Scroll down to
Maven
option and select to install maven automatically. - In
Maven Project Configuration
selectDefault
asLocal Maven Repository
as shown in the figure below Save
this configuration
Steps for clean install
- Goto Dashboard of Jenkins, select Project and click on
Configure
. - Select
Build
>Add a Build Step
>Invoke Top Level Maven Targets
- In this, select
Maven Version
as maven and inGoals
we have to write clean install as mentioned in the following image.
Steps to add a dependency and build the project
- We add a dependency commons-fileupload in
pom.xml
file of the project as follows - Now, go to the
Dashboard
of Jenkins andBuild
the Project
Output of build after adding "commons-fileupload"
dependency
- To demonstrate a build script execution, we have added a shell script
file named
sampleScript.sh
in the WebGoat project directory. - The contents of
sampleScript.sh
file is an echo command which outputs "Hello WebGoat" to the console screen when the project is built
Steps to demonstrate build script execution
- Goto Dashboard of Jenkins, select Project and click on
Configure
. - Select
Build
>Add a Build Step
>Execute Shell
- In the
command
, write "sh sampleScript.sh" which will execute the shell script sampleScript.sh - Goto WebGoat project directory and add a file
sampleScript.sh
which echoes "Hello WebGoat" to the console screen on execution - Now goto Dashboard of Jenkins and build the project
Output of build script execution
To demonstrate multiple nodes, we have created a slave node along with the master node
The following steps are followed to set up a Slave node
- Install NodeLabel Parameter Plugin plugin in Jenkins
- Goto
Manage Jenkins
>Manage nodes
>New Node
- Set the following configuration to the Slave Node as shown in the figure.
- Now, goto Dashboard of Jenkins, select Project and click on
Configure
. - Select on the option
This build is parameterized
- Select both
master
andslave
as default nodes - Select option
Allow multi node selection for concurrent builds
- Select
Execute concurrent builds if necessary
- All the above changes made to the Project Configuration is also shown in the below diagram
- Now goto Dashboard of Jenkins and click on
Build Executor Status
option mentioned in the navigation box in the left - Click on
Slave
and Run the slave node to make it active - Finally goto Dashboard of Jenkins and build the project
Output of the multinode build
- After clicking build, we get the following screen. Select both the nodes and click build.
- We will notice that in the build history, we get two builds in progress where one is master and the other is slave.
- In the console output, we can verify the two builds. This is the master build which ran successfully. This is the slave build which ran successfully.
We can retrieve the status of any build if we know two parameters:
IP Address
orComputer Name
Port Number
on which Jenkins is running
For Example: The name of my computer is set asnkatre-Inspiron-3521
and the port number on which Jenkins is running is 8080
Thus, the status of any build can be accessed by any machine in the network via the following URL:
http://nkatre-inspiron-3521:8080/job/WebGoat/19/
The above URL will show the status of build #19
The following steps are followed to check status via http
- Goto
Manage Jenkins
>Configure System
- In
Jenkins Location
, set theJenkins URL
as http://computer-name:8080/
For Example: In my case it is http://nkatre-Inspiron-3521:8080/ - The below figure shows the settings
- Now to check the status of any previous builds, enter the following URL in the web browser http://nkatre-inspiron-3521:8080/job/WebGoat/19/ This will show the status of build #19