In this lab we will go through creating and executing a Jenkins pipeline. There are two types of pipelines, declarative and scripted.
We’ll be setting up a project whereby code is pulled onto Jenkins, prepared, built, and then the output artifact is saved.
We will be pulling down sample code, written in C language, and compiling it via Jenkins. The sample code is basically a popular CS course exercise for creating Mario-styled (think Nintendo) pyramids. The user provides input for the height of the pyramid. This is beyond the scope of this lab, but the compiled binary being output may not be compatible with all types of Unix systems, due to the platform that it was compiled on.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Log into the Jenkins Server Provided by Hands-on Lab
Once the hands-on lab spins up and provides the public IP of Jenkins server to log into, use the following URL and credentials to log into the Jenkins instance setup for you:
- URL: http://<Public-IP-of-Jenkins-VM>:8080/
- Username:
student
- Password:
OmgPassword!
- Create a New Pipeline Jenkins Job
Once you log into the landing page for Jenkins, click on New Item (on the left side of the screen) to proceed towards selecting the type of Jenkins job you want to create.
Once the new page loads, click on Pipeline. In the input box, give a name to your job such as MyPipeline.
After selecting the type of job, Pipeline, and giving it a name, click on OK to proceed with configuring the job.
- Configuring Jenkins Pipeline Job (Scripted Pipeline)
On the new page which loads for configuring the pipeline job, scroll down to the Pipeline section. Ensure the Pipeline Script option is selected in the Definition drop-down. An input area should be visible.
Copy the following body of text (which is basically in Groovy DSL format, a format understood by Jenkins) into the input area:node { def gccHome = "/usr/bin/gcc" stage('Preparation') { //pull down Mario C code from repo git 'https://github.com/linuxacademy/content-pipelines-cje-labs.git' } stage('Build') { //if system is Unix compile C source code if (isUnix()) { sh "'${gccHome}' --std=c99 -o mario lab1_lab2/mario.c" } else { echo "Not a Unix system, build not possible" } } stage('Results') { archive 'mario' } }
Leave everything else to default settings and click on Save.
- Running Your Jenkins Pipeline Job
From the previous step, after hitting
Save
you will be taken to the control page for the job you just configured, where you can see the job status and other job statistics, including being able to edit the configuration again. <br />
To kick off a build, click onBuild Now
. <br />
This should kick off the build and you should see the output of build status in a couple of places on your current screen.1) Under the
Build History
box to the left of your screen you’ll see a build number and a progress bar if the build is currently running
2) The page will also be updated with aStage View
giving details of execution success(green) and time taken by each build stage that was defined in ourScripted Pipeline
. Subsequent builds will add more data to average run times in the same area.<br />
UnderBuild History
if you click on the build number for example#1
you will be taken to the details of the specific build such asConsole Output
for execution of commands defined in the pipeline for each step. <br />On this page you’ll also find the build output files or
Build Artifacts
which are the outcome of the pipeline stages that you built. You can click on the actual file name shown under build artifacts to download it to your system.