This simple exercise is designed to introduce you to Jenkins and continuous integration. This will be done in teams of 5 but we will all be working on one Jenkins server.
- Fork the repo.
- Set up job in Jenkins to connect to your repository and build C++ hello.cpp.
- Set up build status badge.
- Set up second job to run the program after build completes.
Someone on your team hopefully has a Github account. Sign in to Github and navigate to www.github.com/jbankes/Hello_Jenkins. Go ahead and fork this repository and clone it to a computer. To clone a repository using a Mac/Linux run
$ git clone https://github.com/<your_Github_username>/Hello_Jenkins
After you have cloned the code to a computer please open the README.md file in a text editor. Please put the full names of all group members at the top of the README. Commit the change and push back to Github. Run the following from inside the directory after adding the names to the README:
$ git add README.md
$ git commit -m "Updated README with Names"
$ git push
If there is an error or you can't see your commit in Github after refreshing then let me know.
- Navtigate to Jenkins.
- Click New Item.
- Enter a name for your project, click Freestyle Project, then OK.
- Note: Please do not include a space.
- Name this something unique so there are no collisions.
- Set up Source Code Management.
- Select git.
- Enter the URL to your git repository
- Setting up Build Triggers
- Select Poll SCM.
- Set up cron job by putting in
H/2 * * * *
. - Set up Build.
- Add build step Execute Shell.
- Enter
make
(This will run the Makefile). - Click Save.
The build status symbol often seen on a Github repository is normally connected to TravisCI or JenkinsCI. We are using JenkinsCI which requires a plugin called Embeddable Build Status. I have already installed it for you. You just need to add the proper information into your README.md file.
- Open the README file in a text editor.
- Go to the Embeddable Build Status page. The link is found on the main page of the job.
- Select the Markdown (with View) protected link and paste it in your README.
- Commit your README changes and push to Github.
- The change should automatically cause the job to build and after you can go to Github and check your repo. You should see the build status there
Because we selected With View you will be able to click the build status icon which will take you to the Job in Jenkins.
The final step to this demo is to set up a second job that automatically runs after the project builds. This is different than the other job because this will not have a git repository - it doesn't even build anything.
Just a note: In a real-life scenario you wouldn't run a program through a build job just like this because I/O is not possible via this console. There are other tools people use at this step like SeleniumHQ, SonarQube, or a Deployment. The point of this is to show downstream/upstream job relationships.
- Create a new Job in Jenkins
- Click New Item.
- Enter a name for your second job, click Freestyle Project, then OK.
- Go immediately to build step and select Execute Shell.
- Enter the following Command
/var/lib/jenkins/workspace/<the name of your first project>/hello_exec
- Save
- Set your first job to call the second
- Go to your first job and open the Configure page.
- Scroll to bottom and add a Post-Build Action. Select Build other projects.
- Enter the name of your second job.
- Save
- Run your first job
- Do this by clicking
build now
on the main page. - After that successfully builds go and check your second job.
- You should see it successfully run.
- Select a Build Job from History and go to the console log to see your program output. If you program has run there then you successfully set up a basic pipeline.
As you can see, Jenkins has a ton of opportunity which makes it the leading CI tool for modern enterprise and software development. Jobs don't have to be explicitly build jobs which mean you can do other incredible things like deployments, promotions, testing, feedback, and much more.
Please submit the URL of your group's Github fork to x01 Intro to Jenkins on Blackboard.
Justin Bankes [email protected]
Shane MacBride [email protected]