Jenkins pipeline

Victor Yeo
3 min readJul 6, 2020

--

This article tells how to setup a Jenkins pipeline that pulls source code from github, builds the code and tests it. It helps users to follow and setup similar pipeline. The setup steps are performed on Jenkins 2.235.1 release.

Login to Jenkins webpage. I setup a Jenkins on my local machine, in this case, the url is 0.0.0.0:8080. Go to Manage Jenkins -> Manage Nodes and Clouds

The node name is “master”.

In Jenkins , create a new Pipeline. In the pipeline script, choose Pipeline script from SCM and set script path to Jenkinsfile.

In the github url, create a Jenkinsfile. For scripted pipeline, create the node master. Create three stages.

node (‘master’) {
stage(‘Source’) {
git ‘https://github.com/victoryeo/cppcode/'
}
stage(‘Build’) {
sh ‘make’
}
stage(‘Test’) {
echo “Test”
sh ‘./quotient’
}
}

In the Jenkins web page, click on the Build now option.

After build is completed, in the Build History pane, click on number, e.g. #10 to examine the build history.

Then, click on Console Output to inspect the build log.

For declarative pipeline, create the stages, three stage, and steps.

pipeline {
agent any
stages {
stage(‘Source’) {
steps {
git ‘https://github.com/victoryeo/cppcode/'
}
}
stage(‘Build’) {
steps {
sh ‘make clean’
sh ‘make’
}
}
stage(‘Test’) {
steps {
echo “Test”
sh ‘./quotient’
}
}
}
}

Additionally, in declarative pipeline, we can add triggers to Jenkinsfile to schedule periodic build.

pipeline {
agent any
triggers {
cron('H 9-16/2 * * 1-5')
# the field follows the syntax of cron (with minor differences).
# Specifically, each line consists of 5 fields
# MINUTE HOUR DOM MONTH DOW
# eg. once every two hours every weekday
}
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
}

The Jenkinsfile and C++ code are available at https://github.com/victoryeo/cppcode/

--

--

No responses yet