Create a Pipeline for Java Spring Boot
Deploying a Spring Boot App using Pipeline Strategy with Jenkings on Openshift
Create a fork of the
spring-client
repository,Create a fork in your own GitHub organization, e.g. https://github.com//spring-client
Review Jenkinsfile,
Review the Jenkinsfile that is included in the Spring Client repository,
If you want an in-depth walk-through of the stages and steps in the Jenkinsfile, go to the Indepth Review of the Jenkinsfile,
Edit the Jenkinsfile,
In the
Login
stage, Change the URL and the port to match your login command,
Configure Jenkins
Go to the OpenShift web console,
From the logged in user profile dropdown, click the
Copy Login Command
,
The command should look like,
Copy the OpenShift API token value, e.g.
aaHYcMwUyyusfNaS45aAiQer_Kas1YUa45YTA2AxsNI
,Go to the Jenkins Administration dashboard,
Click
Credentials
, orGo to Jenkins > Manage Jenkins > Configure Credentials
The Jenkinsfile expects the OpenShift API token credential to be available named
openshift-login-api-token
,Go to
Credentials
>System
,In the
System
view, select the dropdown forGlobal credentials (unrestricted)
,
Click
Add credentials
,For
Kind
selectUsername with password
,For
Username
entertoken
,For
Password
paste the OpenShift API token from the OpenShift web console login command,For
ID
enteropenshift-login-api-token
, which is the ID that the Jenkinsfile will look for,For
Description
enteropenshift login api token
,Click
OK
,
4. Create a Personal Access Token to Access the Github API
Go to your Github account > Settings > Developer settings > Personal access tokens,
Click
Generate new token
,Under
Note
addgithub-access-token-for-jenkins-on-openshift
,Select the scopes for
repo
,read:repo_hook
, anduser
,Click
Generate token
,Copy the token, we need it to create our Jenkins pipeline,
5. Make sure a project springclient-ns
exists in OpenShift,
From the cloud shell,
oc new-project springclient-ns
,Before deploying the
spring-client
application, the Jenkinsfile defines a step to delete and create a project. The delete step causes an error when the project it tries to delete is missing, so make sure the projectspringclient-ns
exists in OpenShift,Go to OpenShift >
Cluster Console
,Go to
Administration
>Projects
,Filter projects by
springclient-ns
,If there is no such project, click
Create Project
to create it,
6. Create a Multibranch Pipeline using Blue Ocean,
In the Jenkins Dashboard, click
Open Blue Ocean
to open the Blue Ocean editor,If the
Welcome to Jenkins
popup window shows, click theCreate a new Pipeline
button, or click theNew Pipeline
button in thePipelines
window,
This will create a new
Multibranch Pipeline
,Select the
GitHub
option,
In the
Connect to GitHub
section, paste the personal access token you created in your Github account,
Click
Connect
,Select the organization to where you forked the Spring Client repository,
Search for and select the
spring-client
repo,
Click
Create Pipeline
,When the pipeline creation is completed, a build is triggered automatically,
Immediately, a build is triggered,
You should see a successful build of the pipeline,
If an error occurs, you can debug the pipeline,
A red cross on a stage, will indicate the pipeline broke in that stage,
Unfold the step in the stage, to see the log output,
Any update to the Github repository, e.g. a push to update the Jenkinsfile, source code of the Spring Boot application, or the README.md file, will trigger a new build of the pipeline,
If you're interested, review the pipeline settings:
Click the Configure option,
Review the settings,
Get the route
Test the deployment,
Last updated