This is a self-assessment activity to give you practice in working with the Jenkins
continuous integration system. Feel free to share your problems, experiences, and choices in the Forum.
In a previous assignment, you set up a project with an automated build and some unit tests, all controlled by ant
. We’ll use that as the starting point for this lab.
Create a public project on GitLab and push your project code up to there.
On a separate page/tab, log in to Jenkins. Use the “New Item” link to start setting up a new Jenkins project.
Pick a name and select “freestyle”. Click OK.
On the next page, type in an appropriate description.
I prefer that people not run builds on the Jenkins server itself (to avoid clogging the server if someone submits a particularly lengthy build or, worse, tests that get caught in an infinite loop). Instead, we want to use separate “runner” nodes whenever possible. Look down a little and check the box “This build is parameterized”.
Click “Add Parameter’ and select ”Node“. For the default node, use any of the ”runner“ nodes. For the possible node lists, select ”All Nodes". (This allows Jenkins to switch to a different runner if the default one is tied up.)
Select Git
for the Source code management. Now, because we are working with a public project, Jenkins will not need any special credentials to get a copy of your project. Go back to the page with your GitLab project. Get the HTTP URL for your repository, and enter it as the Jenkins Git URL.
Wait a few seconds, and you should get a confirmation message indicating that Jenkins was able to find your repository. If not, look carefully at the URL and the message.
Skip down to Build Triggers. Select Poll SCM
, and enter the timing code
H/15 * * * *
to check your repository once every 15 minutes. (That’s a bit much in practice, but we won’t be keeping this project around all that long.)
For the Build step, indicate that you want to run ‘ant’. Enter the appropriate build target.
By default Jenkins will look for the build.xml
file in the top directory of your repository. But if you have followed the usual Eclipse/git conventions, your build.xml
file will be in a directory below that. Click the Advanced...
button and enter the actual path to your build.xml
file, relative to the top of your repository.
Save your project.
You could wait 0 – 15 minutes for your project to build, but until you are sure that you have the project set up correctly, it’s easier to use the Build Now
link to force an immediate build.
When the build finishes, clink on it in the Build History and then check the Console Output
link. If the build did not run properly, use the info from the console output to adjust your build parameters. (You can edit your project settings by returning to the project page and selecting Configure
.)
Once your build succeeds, if your build.xml
file produces a JUnit report, or Javadoc documentation, try editing your project settings on Jenkins (Configure
) and adding a Post-Build Action
to publish your report/documentation.
Force another build. You should see a link to your report/documentation appear in the central/main project description area. If you chose JUnit, you should get a “Test Result Trend” graph, which will be a bit boring because one point does not make for much of a trend. But clock in the graph and you will see your detailed test report.
Things get a bit trickier if Jenkins needs to supply credentials to GitLab in order to check out your project. This would have been necessary if your project had not been public.
In theory, you could supply an ssh key pair for this purpose, but this turns out to be fairly hard to manage. We’ll instead take advantage of the fact that these two servers have been set up to cooperate with one another. Gitlab has a special user name reserved for the Jenkins server, and can notify Jenkins when anything is checked in to your Gitlab repository.
On Jenkins, take note of the URL for your project, e.g., ‘http://forge350.cs.odu.edu:8080/job/projectName/’
Edit your Gitlab project settings,
/buildWithParameters
command to that.%
codes. For example, blanks in your project name would be replaced by %20
.Edit the Configuration settings of your Jenkins project.
For the Git repository URL, use the ssh:
URl of your GitLab project.
This must start with ssh://
, i.e., ssh://git@forge350.cs...
.
Gitlab sometimes puts a colon (‘:’) between the machine name and the start of the path in the ssh
URL. If you see that, change it to a ‘/’.
For example, if GitLab says that the ssh
URL of your project is git@forge350.cs.odu.edu:jdoe/projectName.git
, you should give that to jenkins as ssh://git@forge350.cs.odu.edu/jdoe/projectName.git
Just under that URL, for “Credentials” select jenkins.ci
.
Change the “Build Triggers” setting to “Trigger Builds remotely”. For the authentication token, enter the password/token you chose in the prior step.
Save your configuration changes in Jenkins.
Try making a small change to your project (maybe break one of your Unit tests so you can see the difference in your test results report), commit and push that change to your GitLab repository, and wait another 15 minutes.
You should see Jenkins report both the fact that you committed a change, but also you should see a new build in the Build History. Click on it and check the console output and test results.
Please delete your Jenkins and Gitlab projects for this lab when you are done.