Skip to content

03_Manage_Projects

Abhishek Dubey edited this page Oct 18, 2020 · 9 revisions

Manage Project

In this lab we will explore how we can manage Project in Jenkins :

  • Create a Freestyle Jenkins project with a continuous execution every 5 minutes.
  • Modify the above Jenkins project to get any latest committed code in the last 5 minutes.
  • Create a downstream maven project that will build the artifact and saves the artifact. Make sure that it uses the code checked out from the parent job.
  • Create a downstream project that will clean up the workspace.
  • Ensure that none of these 3 projects can have more than 10 execution and that also a maximum of 5 days.
  • Modify the first project to take a branch name as the name so that an end-user can run the project for a specific branch.

Freestyle Job which will execute at every 5 min

  • Go to Jenkins main page and click on the "New Item" at the left-hand bar of Jenkins

  • Click on the "Freestyle Job" and give a name to the Jenkins job

  • Go under the "Source Code Management" and select the Git option and provide the repository URL of the worked repo.

  • Then go to the "Build Triggers" section and select the "Build periodically" option and provide the cron expression for every 5 minutes

  • Then save and run the job by clicking on the "Build Now" option.

  • Once the job is built click on the blue ball which is along with the build-id.

  • Also, you can wait for 5 minutes and see if the job is triggered by itself or not.

Jenkins Job modification to run only when a new commit is made

  • Go to the configure option of the Jenkins job

  • Disable the "Build periodically" option first.

  • Then go to the "Build Triggers" section and select the "Poll SCM" option and provide the cron expression for every 5 minutes

  • Save the job and go to the forked repo. Add a blank line in the README.md file and wait if the job gets triggered by itself or not.

Downstream Maven Project

  • Go to the configure option of the Jenkins job of existing job "<team_name>-checkout"

  • In the "General" click on the "Advanced" section

  • After that enable the check on "Custom Workspace" and provide the path of your workspace like:-
/tmp/<team_name>
  • Then save and run the job by clicking on the "Build Now" option.

  • After that, create a new job with the name <team_name>-maven-project and click on the Freestyle project job type

  • In the "General" click on the "Advanced" section

  • After that enable the check on "Custom Workspace" and provide the path of your workspace like:-
/tmp/<team_name>
  • Go to the Build Section of the job and select the Execute shell.

  • Paste the snippet in Execute Shell block
cd SampleJavaWebApp; mvn clean package

  • Go to the previous job "<team_name>-checkout" and click on Configure. Then go the "Post-Build Actions" and click on "Build other projects".

  • Provide the name of the Maven Jenkins project like - <team_name>-maven-project. Then save and run the job

Workspace Cleanup Downstream Job

  • Create a new job with the name <team_name>-workspace-cleanup and click on the freestyle project job type

  • Go to the "Post-build Actions" and add a post-build action

  • Click on "Delete workspace when build is done"

  • In the "General" click on the "Advanced" section

  • After that enable the check on "Custom Workspace" and provide the path of your workspace like:-
/tmp/<team_name>
  • Save the Job

  • Once the changes are done go to the "<team_name>-checkout" job and go to the "Post-build Actions" and provide the name of the cleanup job with a comma "<team_name>-workspace-cleanup" and then save the job.

  • Click on the "Build Now" option of "<team_name>-checkout" job

Build History Changes

  • Go and configure the all jobs "<team_name>-checkout", "<team_name>-maven-project" and "<team_name>-workspace-cleanup" and under the "General Section" click on the "Discard old builds"

Branch as a Parameter modifications

  • Go and configure the <team_name>-checkout job and under the "General Section" click on the "This project is parameterised".

  • Click on "String Parameter" and provide the name "BRANCH_NAME" and Default value "master"

  • Click on the "Build with Parameters" and build the job.

Clone this wiki locally