Creating & Building a Jenkins Pipeline Job
Ø Executing Jenkins Pipeline From Github (Jenkinsfile)-lab 6
In this exercise, you will build a simple pipeline for a sample application. You will gain a basic familiarity with how a Jenkins Pipeline is created and how to implement simple build logic within a pipeline.
The Scenario
Your
team is building a java app. You have been asked to build a Jenkins Pipeline
app. The pipeline project needs to build the code, run the automated tests, and
deploy artifact that is created by the
build.
Follow the steps given below to create and build our pipeline.
SETUP
YOUR CODE REPO AND JENKINS
Ø First, we need to go to this code and fork the:
https://github.com/mf210/django_demoapp_devops
In the last section, we
used the pipeline script directly on Jenkins. In this section, we will look at
how to execute a pipeline script available in an SCM system like Github.
Before we can test
this in Jenkins, we need to get an API key from GitHub so Jenkins can pull down
this source code from GitHub. To do this:
v Click
your avatar in the top right corner
v Click
Settings.
v Click
Developer settings.
v Click
Personal access tokens > Tokens (classic).
v Click
Generate new token > Generate new token (classic).
v Note:
jenkins.
v Check
the box next to admin:repo_hook.
v Generate
token.
v Copy
the generated token to the clipboard.
Lets Build the
Pipeline in Jenkins
·
In Jenkins, click New Item.
·
For the item name, type my_first_pipeline,
and select Multibranch Pipeline. Click OK.
·
Under Branch Sources, click Add source,
and select Git.
·
Under Credentials, click Add, and select
Jenkins.
·
Username: Enter your GitHub username.
·
Password: Paste in the API key you copied before.
·
ID: github_key
·
Description: GitHub key
·
Click Add.
In the new Git section under Branch Sources, click the
Credentials dropdown and select the credential you just created. For Project
Repository, copy and paste in the URL of your personal fork of the source code
repository. Click Save.
The initial build will take several minutes to
complete.
No comments:
Post a Comment